So I have been getting this error. I know that means that I am doing an illegal operation (trying to maybe loop through strings?), but I thought strings were iterable in a list!!
def censor(text, word): wordlist = text.split(" ") for i in wordlist: if i == word: i = len(wordlist[i]) * "*" " ".join(wordlist) return wordlist
What I have here is:
Line 1: a piece of text and a word as inputs x and y.
Line 2: a variable, wordlist. It splits the text into chunks of words and forms a list with strings as indices. Right?
Line 3: For “every index” (in this case, words) in this list I just made…
Line 4: if this word matches the input y (from above)
Line 5: change the word to *'s multiplied by the length of i (still the string).
Where does my logic fall apart?
Edit: I changed
i = len(wordlist[i]) * "*"
i = len(i) * "*"
I feel like I am getting close. It’s not censoring my text. Back to the drawing board… but I feel like I am on the right track.