Message172855
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 |
|
Date |
User |
Action |
Args |
2012-10-14 07:27:28 | Ian | set | recipients:
+ Ian |
2012-10-14 07:27:28 | Ian | set | messageid: <1350199648.26.0.090631048797.issue16225@psf.upfronthosting.co.za> |
2012-10-14 07:27:28 | Ian | link | issue16225 messages |
2012-10-14 07:27:27 | Ian | create | |
|