Censor spam?

What have I done? I get the following print:
hey hey hey
the password is spam
hey hey hey

Where does the spam sentence come from? Very confusing : )

With the following code

def censor(text, word):
for word1 in text.split():
if word1 == word:
word1 = “*” * 4
print “”.join(text)

censor(“hey hey hey”,“hey”)

a test case from the exercise.

Aha, thought my code created an abomination : )

1 Like

I’ve managed to get a step further with the following code:

def censor(text, word):
list_text = text.split(" “)
new_text = []
for word1 in list_text:
if word1 == word:
new_text.append(”*" * len(word))
elif word1 != word:
print " ".join(new_text)

censor(“this hack is wack hack”, “hack”)

But it still returns more than the sentence I enter:
this **** is wack ****
the password is ****

None is “default” returned value (implicit)