Censor help



Censor help
15. Practice Makes Perfect

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

My code seems to only be going through the first word, then stopping, would someone mind helping me out

def censor(text, word):
    text = text.lower()
    split = text.split(" ")
    length = len(word)
    print (split)
    new = ""
    for i in split:
        if i == word:
            i = ("*" * length)
        return i
    print " ".join(split)


For starters, we do not need to convert to lowercase.

It is rarely a good idea to use a function name as a variable.

This will not change the list.

Inside the loop; too much indentation.

That's a few things to adjust. You might work out the rest in the meantime.


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