Need help with Censor


I'm not sure why my code isn't working for Censor. Thanks.

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

Not sure why it isn't working.

def censor(text, word):
    censored = []
    split = text.split()
    for thing in split:
        if thing != word:
            censored = censored.append(thing)
            asterisks = '*' * len(thing)
            censored = censored.append(asterisks)
    censored = " ".join(censored)
    return censored


Method append adds an element to the end of the list. It does not return a new list, it changes the original object.

What method append returns? None.

So... to add new element to the censored list you simply need this:


That is all. Do not assign the return value to censored, because it will change value to None.


Thanks! It worked :slight_smile:


Great! You're very welcome :slight_smile:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.