Censor


#1



Every time I run my code I keep getting the error "Does your censor function take exactly two arguments, a text string and a word to replace with asterisks? Your code threw a "'str' object does not support item assignment" error." and I'm not exactly sure what the 'str' error is.
My code:


def censor(text, word):
    for i in text:
        if i in word:
            text[(text.index(i))] = "*"
    print text      
            
 .


#2

here:

text[(text.index(i))] = "*"

strings are immutable, so you can't use square brackets to update a specific index in string


#3

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