Here is my code:
def censor(text, word): x = text.split() for i in x: if i == word: x.remove(word) x.append('*' * len(word)) text = " ".join(x) print text censor('yes yes yes yes', 'yes')
My code returns: “yes yes *** ***”
Question: Why are the last two items in list x being iterated but not the rest? I was thinking that the “for i in x:” action iterated through all of the indexes in x. Any help is much appreciated!