Censor Struggles


Section: Practice Makes Perfect
Challenge: Censor

Link to this part of the course: censor

I can't seem to get this figured out. I've perused the other posts but it's just not clicking. I've posted my code below, but I keep getting the following error:

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

So I've done something right if it's doing the "*** *** ***" part, but how do I get rid of the first 3 "hey"s????

def censor(text, word):
    new_txt = text.split(" ")
    for i in new_txt:
        if i == word:
            new_word = "*" * len(word)
    return " ".join(new_txt)


Maybe you should make an empty list named something else and append new_word to that.
If the word is not a censored word, then append the word to the empty list instead. So you'll have two conditions.


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