Censor


#1

Error Message:
"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 "list indices must be integers, not str" error."

Not entirely sure what i've done wrong, thought it would censor a word in text that == the variable word, but throws me an error instead.

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

#2

words will hold the words from text, look:

def censor(text, word):
    text2 = text.split(" ")
    for words in text2:
        print words
print censor("hey hey hey","hey")

if you want to use indexes, use range()


#3

so basically if i use the "for words in text2" format its going input the words in the list instead off the indexses?. Thanks for the super fast reply by the way :smiley:


#4

well, if you ran the code i provided, you would have seen this would be the case


#5

Thanks, that did the trick and again thanks for quick answer you really helped me out.


#6

good to hear you have it resolved :slight_smile:


#7

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