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 Ian
Recipients Ian
Date 2012-10-14.07:27:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1350199648.26.0.090631048797.issue16225@psf.upfronthosting.co.za>
In-reply-to
Content
I'm new to Python and I've hit what appears to me to be a bug, but may be a "feature", so a tutorial bug. 
I tried to loop through the items in a list, test each and remove those which fail the test.

Simplifying to illustrate:
>>> print test
[1, 2, 3, 4, 5]
>>> for item in test:
...     print item
...     test.remove(item)
... 
1
3
5
>>> print test
[2, 4]

Whereas I would expect to see all items looped through and non left in the list.
I have worked with languages where you are explicitly warned that you must not mess with the loop variable, or where the behaviour you will get is explained in detail, so you can use it. Not having anything flagged up in eg 5.6. Looping Techniques on
http://docs.python.org/tutorial/datastructures.html
I assumed that the behaviour would be safe and intuative.
Yours
Ian
History
Date User Action Args
2012-10-14 07:27:28Iansetrecipients: + Ian
2012-10-14 07:27:28Iansetmessageid: <1350199648.26.0.090631048797.issue16225@psf.upfronthosting.co.za>
2012-10-14 07:27:28Ianlinkissue16225 messages
2012-10-14 07:27:27Iancreate