I get error: 'Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "hey hey hey" when it should return "*** *** ***".'
I expected my code to break the string (text) into a list (newtext), and then iterate through each item and replace the item with ***'s if it matched (word). Unfortunately, for some reason I don't understand, it won't do that. Now, I have gotten the lesson to work if I switch to using the format
newtext[newtext.index(i)] = "*" * len(word) instead of what appears below at line 8. However, I don't understand at all why that is any different from just using i.
Please explain for me!
P.S. You can remove the 'print' statements. I was just using them to see where the problem was occurring in my code.
def censor(text, word): newtext = text.split() print newtext for i in newtext: print i if i == word: print word i = "*" * len(word) print i return " ".join(newtext) print censor("I love to eat birds with eat", "eat")