10. censor



Oops, try again. Does your censor function take exactly two arguments, a text string and a word to replace with asterisks? Your code threw a "sequence item 0: expected string, builtin_function_or_method found" error.

I'm trying to replace the "i"th element of "lis" by the number of asterisks as the length of word/low. When trying to put them back, it throws this error. What is going wrong?

def censor(text, word):
    low = word.lower
    lis = text.split()
    a = len(word)
    for i in range(0, len(lis)):
        lis[i] = lis[i].lower
        if (lis[i] == low):
            lis[i] = "*" * a
    new_str = " ".join(lis)
    return new_str

print censor("this wack is hacking wack", "wack")


Hello @digitalace60942,

Try putting a space as the argument of your .split(" ") method, and try putting parentheses after your .lower() method calls. That should fix your problem...


Well, now the error is gone, but I still can't censor the word.


here's my definition for the problem with a twist of a raw_input:

text = raw_input("sentence")
word = raw_input("censored")
def censor(text, word):
return text.replace(word, "*" * len(word))
print censor(text)