ceciliasei...@gmx.de, 23.01.2010 17:29:
> Arnaud Delobelle wrote:
>> ceciliasei...@gmx.de writes:
>>
>>> 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:
> 
> Ouch... thanks Arnaud... The stable way would've been
> 
> for w in l1[:]: #use copy of l1 for iteration
>     print(l1.pop()) #decomposite list

If the intention is to exhaust the list during the iteration, I'd go for this:

    while l1:
        print(l1.pop())

Stefan
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to