I'm getting an error that says "Your function fails on censor("hey hey hey","hey"). It returns "he* he* he*" when it should return "*** *** ***""
I've tried several different things, none of them worked, and when I came to this forum to see if anyone else has struggled with this, I noticed that many of the solutions require converting var word and var text to a list first. I was wondering: is there a way to solve this challenge with strings, or is there no way to censor words without converting them to lists first?
My code (that's generating the error):
def censor(text, word): censored_text = "" censored_word = "" for i in word: censored_word = word.replace(i, "*") if word in text: censored_text = text.replace(word, censored_word) return censored_text