Apr-24-2017, 09:44 PM
>>> items = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> for ndx, item in enumerate(items): ... print("{0} => {1}".format(ndx, item)) ... items.remove(item) ... 0 => 0 1 => 2 2 => 4 3 => 6 4 => 8 5 => 10 >>> items [1, 3, 5, 7, 9]The for loop keeps track of what index it's at, but when you change the underlying list, the index stays the same... it's just going to refer to a different element. So you don't iterate over the whole list, but it is at least predictable. Predictable, at least, if that's what you were expecting. I still think you either shouldn't modify the list, or use a while loop and only ever use the first element.