10. Censor, help!


#1

def censor(text, word):
    text_list = text.split()
    for a in text_list:
        if a == word:
            a = "*" * len[a]
    return " ".join(text_list)

print censor("hey, hey, you", "hey")

i don't know why it doesn't working.. please help.
i think the problem is about convert 'a' to '"*" * len[a]'


#2

And you would be correct. But in a weird sort of way. Nothing is happening. Examine your code. What is happening? I mean, really, tell us; what is happening?


#3

thanks very much for your comment.

it says,

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 "'builtin_function_or_method' object has no attribute 'getitem'" error.

and outcome is hey, hey, you
censor doesn't even work.


#5

def censor(text, word):
replace_txt = ''
counter = 0
while counter < len(word):
replace_txt = replace_txt + '*'
counter += 1

return text.replace(word,replace_txt)

#6

This worked for me:

def censor(text, word):
j = []

for i in range(0, len(word)):
    j.append(word[i])
b = word
for i in range(0, len(j)):
    j[i] = "*"

p = "".join(j)
return text.replace(word, p)

#7

thank you for your help
@fayalif, @tagblaster90092