Fanny’s Occurences

The problem is that when you are supposed to remove a character, you are replacing it with a space, when you should be replacing it with an empty string.

Another potential problem (although not exposed in these examples) is that you are calling strip() (which will remove leading and trailing whitespace) when the specification does not say that you are meant to do this. (In some cases, it could mask the previous bug, if the space that you wrongly added was at the start or end of the string.)

Where you have:

    Str= Str.replace(Sub, " ")     
    return Str.strip() 

you should use:

    Str= Str.replace(Sub, "")     
    return Str

or simply:

    return Str.replace(Sub, "")     

Leave a Comment