Stuck on censor. Please Help!


Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***".

def censor(text, word):
    for i in range(0, len(text.split())):
        if text.split()[i] == word:
            text.split()[i] = "*" * len(word)
    return " ".join(text.split())


i would use split() before the loop so the changes to list persist