This question is regarding the lesson Censor in the Learn Python 2 module:
I am told that my code fails for the phrase censor(“hey hey hey”,“hey”), but it appears to work properly (here and on other phrases I’ve tested). I do not use the " ".join(list) command, but I do not understand why this is necessary / what it does better.
My code is as follows:
def censor(text,word): x = text.split() length=len(word) bleep = "*" * length temp = "" for w in x: if w==word: temp = temp + " " + bleep else: temp = temp + " " + w return temp print(censor("hey hey hey","hey"))
Any help is appreciated - thanks!