iterate over list while changing it
Дамјан Георгиевски
gdamjan at gmail.com
Wed Sep 30 20:44:13 EDT 2009
>> a = [1, 2, 3, 4, 5, 6]
>>
>> for i, x in enumerate(a):
>
> If you change a list while iterating over, start at the tail.
>
> ...reversed(enumerate(a))
Python 2.6.2 (r262:71600, Jul 20 2009, 02:19:59)
>>> a = [1, 2, 3, 4, 5, 6]
>>> reversed(enumerate(a))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: argument to reversed() must be a sequence
> no such list method, which mean you did not run the above before
> posting. Boo!
--
дамјан ( http://softver.org.mk/damjan/ )
Teaching a pig to sing wastes your time & annoys the pig.
More information about the Python-list
mailing list