I have a list of four numbers:
mylist=[3,5,67,4]
I want to remove all the odd numbers. So, I've written the following:
for item in mylist:
if item%2==1:
mylist.remove(item)
When I print mylist
, I get the following:
[5,4]
I cannot figure out why this is happening. However, when I add a print statement after the if
statement I get the correct answer:
for item in mylist:
if item%2==1:
mylist.remove(item)
print mylist
which yields:
[4]
What's going on here? What am I missing?