10. censor


#1



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

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")

#2

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...


#3

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


#4

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):
text.split()
return text.replace(word, "*" * len(word))
print censor(text)