15. Censor Right answer but still shows error



My code gets the right answer but it still shows this error:

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

What is wrong?

def censor(text,word):
    string = []
    for w in text.split():
        if w == word:
            string.append('*' * len(word) + " ")
            string.append(w + " ")
    return ''.join(string)


Use the join() statement to insert a space separator. Don't include the space character in your .append() statements.


Thanks so much!! :grinning:That question was really bugging me.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.