iterating lists

ceciliaseidel at gmx.de ceciliaseidel at gmx.de
Sat Jan 23 10:13:20 EST 2010


As you were talking about list.pop()...

Is anyone able to reproduce the following and explain why this happens 
by chance? (Using 3.1.1)

l1 = ["ready", "steady", "go"]
l2 = ["one", "two", "tree"]
l3 = ["lift off"]

for w in l1:
    print(l1.pop())  #prints only "go steady" - why not "ready"??

for w in range(len(l2)):
    print(l2.pop())  #prints "three two one" as expected
   
for w in l3:
    print(l3.pop()) #prints "lift off" - inconsistent to first case...


At least for 2.2.3 I found the first way to iterate the list as default, 
I guess it is deprecated now but still what happens seems weird to me...



More information about the Python-list mailing list