10. censor - unknown issues!



The error (python doesn't throw an error, it's codecademy's error) is: Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "['hey', 'hey', 'hey']" when it should return "*** *** ***".

I expected the parameter word to change to asterisks (the amount in the word parameter) every instance in the parameter text.

def censor(text, word):
    text_split = text.split()
    word_length = len(word)
    x = -1
    for i in text_split:
        x += 1
        if text_split[x] == word:
            text_split[x].replace(text_split[x], word_length * '*')
    return " ".join(text_split)


String.replace returns a new string, it does nothing to the original (because strings can't be changed)

You're also returning a list, that's a different data type from what the function should return

Perhaps, instead of using String.replace, you should replace by assinging a different string at that location in the list.

String.replace can do the censoring in one line, so it makes the exercise rather silly.