Thursday, 15 August 2013

Modify the list that is being iterated in python

Modify the list that is being iterated in python

I need to update a list while it is being iterated over. The code has more
or less the following structure:
for item in some_list[:]:
...
...somecode...
...
some_list = some_list_updated
It seems that the list does update appropriately when I print it out, but
python keeps iterating over the old list, it seems. What is the
appropriate way to go about it - if there is one? Thanks a lot!

No comments:

Post a Comment