H=[1,2,3,4,5,6,7,8]
for h in H:
print h
if h%2==1:
H.remove(h)
print H
Output:
1
[2, 3, 4, 5, 6, 7, 8]
3
[2, 4, 5, 6, 7, 8]
5
[2, 4, 6, 7, 8]
7
[2, 4, 6, 8]
So, I was just experimenting with the posibility of modifying a list inside a for loop over the same list, and while the list itself behaves like I thought, I don't get why the numbers 2,4,6,8 aren't being printed. Can anyone explain?