I was wondering: When I should just replace a part of a string, why do I have to loop and split the string? Why not just replace the string instead? I tried:
def censor(text, word): pixelword = len(word) * '*' text.replace(word, pixelword) return text
Your function fails on censor(“hey hey hey”,“hey”). It returns “hey hey hey” when it should return " *".
Any idea why this doesn’t work?