Censor error issues


#1



So I'm working on Censor, and even though I've come up with a working solution, it keeps telling me that its not working.

Here is my code.

def censor(text, word):
    split_text = text.split()
    new_text = []
    for x in split_text:
        if x == word:
            new_text.append(len(x)*"*")
        else:
            new_text.append(x + " ")
    return " ".join(new_text)

But it keeps giving me an error message saying:

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

I've tried some other text strings and words to censor and its always printed correctly. Any thoughts?


#2

here:

new_text.append(x + " ")

why append " "? you use " ".join() to take care of the spaces between words, why add even more spaces when appending to new text?


#3

Ah, thank you, I see now. All resolved.


#4