Censor


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/1/4?curriculum_id=4f89dab3d788890003000096#


I got the following message
Oops, try again. Your code looks a bit off--it threw a "'NoneType' object has no attribute 'append'" error. Check the Hint if you need help!


I assume .append() is how you add item to the end of a list and I already created an empty list name t. Please help.


def censor(text, word):
    t = []
    for w in text.split():
        if w == word:
            t = t.append("*" * len(w))
        else:
            t = t.append(w)
    print " ".join(t)


#2

.append() will update the list for you, and return None

so by storing the result of append in a variable, you store None in t, next time you try to append to None, which doesn't work


#3

Hi ,

Thank you!
I changed my code to
def censor(text, word):
t = []
for w in text.split():
if w == word:
t.append("*" * len(w))
else:
t.append(w)
print " ".join(t)

I called the function and it did return the correct result but I still received the following message:
Oops, try again. Your function fails on censor("hey hey hey","hey"). It returns "None" when it should return "*** *** ***".


#4

much closer, but you need to return the censored string, not print it


#5

Thanks! Now I got the correct one.


#6