Hi everyone, I'm stuck at this exercise. It says: Your function fails on censor("hey hey hey","hey"). It returns "***" when it should return
"*** *** ***"

Can anyone see the problem? Thanks!

def censor(text,word):
    string_list = text.split()
    for item in string_list:
        if item == word:
            return "*" * len(item)
    new_text = " ".join(string_list)
    return new_text


a function ends the moment a return keyword is reached, if this happens in a loop, the loop simply breaks, so your function ends:

return "*" * len(item)

at this line


So how can I fix it?



not use return inside the for loop.

How did you think you where to censor the words in text?


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