I have the following Python-code which is supposed to read through this list. If a word's length is not 3, the word should be removed from the list:
stuff = ["apple", "jam", "banana", "bread", "corn", "orange", "tea", "peanut"]
for word in stuff:
if len(word) == 3:
pass
else:
stuff.remove(word)
print(stuff)
But as I print the list, I get the following output:
['jam', 'bread', 'orange', 'tea']
But it should look like this:
['jam', 'tea']
Help would be highly appreciated!