This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author chris.jerdonek
Recipients Ian, chris.jerdonek, docs@python, georg.brandl, serhiy.storchaka
Date 2012-10-14.19:38:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1350243522.79.0.0905439715454.issue16225@psf.upfronthosting.co.za>
In-reply-to
Content
> But in general the advice should be: if you want to insert or remove elements during iteration, iterate over a copy.

I would expand this to cover changing the list in any way.  I think the point being made is that iteration doesn't implicitly make a copy.  There are cases where modifying the list in place can also yield unexpected results.  For example (naive list reversal):

>>> words = ['cat', 'window', 'defenestrate']
>>> for i, word in enumerate(words):
...     words[-i-1] = word
... 
>>> words
['cat', 'window', 'cat']
History
Date User Action Args
2012-10-14 19:38:42chris.jerdoneksetrecipients: + chris.jerdonek, georg.brandl, docs@python, serhiy.storchaka, Ian
2012-10-14 19:38:42chris.jerdoneksetmessageid: <1350243522.79.0.0905439715454.issue16225@psf.upfronthosting.co.za>
2012-10-14 19:38:42chris.jerdoneklinkissue16225 messages
2012-10-14 19:38:42chris.jerdonekcreate