I am a bit stuck on this one. Currently, my code is:
def censor(text, word): word = str(word) chunks = text.split(" ") #print chunks for item in chunks: if item == word: item = "*" * len(word) return chunks #" ".join(chunks)
I get the following error message:
Your function fails on censor("hey hey hey","hey"). It returns "['hey', 'hey', 'hey']" when it should return " *".
So I know the list is not falling through the loop, but I have no idea why that happens. I know the function is not complete, but why it is not even touching the list I cannot understand.
Also, when I leave the
join statements uncommented, the system returns the following message:
Traceback (most recent call last): File "python", line 10, in <module> NameError: name 'chunks' is not defined
But then proceeds to print one of the test arguments the system is passing (
['the', 'password', 'is', 'spam']). How can it state that the variable is not defined, but at the same time print it?
This baffles me…