Here is what's going on. Suppose you have this list:
['a', 'b', 'c', 'd']
and you are looping over every element in the list. Suppose you are currently at index position 1:
['a', 'b', 'c', 'd']
^
|
index = 1
...and you remove the element at index position 1, giving you this:
['a', 'c', 'd']
^
|
index 1
After removing the item, the other items slide to the left, giving you this:
['a', 'c', 'd']
^
|
index 1
Then when the loop runs again, the loop increments the index to 2, giving you this:
['a', 'c', 'd']
^
|
index = 2
See how you skipped over 'c'? The lesson is: never delete an element from a list that you are looping over.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…