Censor


#1


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

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

#2

here:

for i in newText:

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


#3

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