I'm trying to iterate over list with items. When the item is processed I want to delete the item and write the list into the file. But there is a problem that only items on even positions are deleted.
Here is a very simple example:
>>> x = [1,2,3,4,5,6,7,8,9]
>>> for i in x:
... print x
... x.remove(i)
... write_x_into_the_file()
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[2, 3, 4, 5, 6, 7, 8, 9]
[2, 4, 5, 6, 7, 8, 9]
[2, 4, 6, 7, 8, 9]
[2, 4, 6, 8, 9]
I think that it is because it iterates using index incrementation. Do you know some pythonic workaround?