Need help with Censor


#1


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)
        else:
            asterisks = '*' * len(thing)
            censored = censored.append(asterisks)
    censored = " ".join(censored)
    return censored


#2

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:

censored.append(thing)

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


#3

Thanks! It worked :slight_smile:


#4

Great! You're very welcome :slight_smile:


#5

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