Sobes.tech
Junior — Senior

Correcting the removal of a substring at the beginning of a string

livecode

Task condition

The function dif_str(source: str, prefix: str) -> str should remove prefix from source only if source starts with prefix, and only remove one occurrence at the beginning. The current implementation removes all occurrences, which needs to be fixed.

def dif_str(source: str, prefix: str) -> str:
    if source.startswith(prefix):
        return source.replace(prefix, '')
    return source

print(dif_str("how how how", "how"))