On Wed, Sep 30, 2009 at 11:19 PM, Daniel Stutzbach
dan...@stutzbachenterprises.com wrote:
On Thu, Sep 24, 2009 at 3:32 PM, Torsten Mohr tm...@s.netic.de wrote:
a = [1, 2, 3, 4, 5, 6]
for i, x in enumerate(a):
if x == 3:
a.pop(i)
continue
if x == 4:
a.push(88)
In article mailman.430.1253826262.2807.python-l...@python.org,
Terry Reedy tjre...@udel.edu wrote:
Torsten Mohr wrote:
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.
This only applies if you add/remove elements; simply
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,
On Thu, Sep 24, 2009 at 3:32 PM, Torsten Mohr tm...@s.netic.de wrote:
a = [1, 2, 3, 4, 5, 6]
for i, x in enumerate(a):
if x == 3:
a.pop(i)
continue
if x == 4:
a.push(88)
print i, i, x, x
I'd like to iterate over a list and change that list while
iterate over a copy of the list:
for i, x in enumerate(a[:]):
Always worked for me ;)
--
http://mail.python.org/mailman/listinfo/python-list
Hello,
a = [1, 2, 3, 4, 5, 6]
for i, x in enumerate(a):
if x == 3:
a.pop(i)
continue
if x == 4:
a.push(88)
print i, i, x, x
I'd like to iterate over a list and change that list while iterating.
I'd still like to work on all items in that list, which is not
Torsten Mohr wrote:
Hello,
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))
if x == 3:
a.pop(i)
del a[i] # you already have the item
continue
if x == 4:
On Thu, Sep 24, 2009 at 4:32 PM, Torsten Mohr tm...@s.netic.de wrote:
Hello,
a = [1, 2, 3, 4, 5, 6]
for i, x in enumerate(a):
if x == 3:
a.pop(i)
continue
if x == 4:
a.push(88)
print i, i, x, x
I'd like to iterate over a list and change that list while
On Thu, 24 Sep 2009 21:32:53 +0100, Torsten Mohr tm...@s.netic.de wrote:
Hello,
a = [1, 2, 3, 4, 5, 6]
for i, x in enumerate(a):
if x == 3:
a.pop(i)
continue
if x == 4:
a.push(88)
print i, i, x, x
I'd like to iterate over a list and change that list