Your code threw a "list indices must be integers, not str" error.

I have been trying to work out this problem for a while. It seems like this should work but it keeps giving me the above error message. Any help would be great!

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



for i in newText:

i contains item from lists, not indexes. if you want indexes, use range() in your for loop


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