python said : "1, 2, 3, 6, 7, manbo !"

Edward C. Jones edcjones at erols.com
Thu Jan 22 09:56:04 EST 2004


Erik Max Francis wrote:
> - wrote:
> 
> 
>>Why 5 does not appear ? (this was the source of a deep bug in a 4000+
>>lines networked program...)
> 
> 
> You are iterating over a mutable sequence while you are mutating it. 
> That is a big no-no.

This can sometimes be done safely by iterating backwards:

n = len(seq)
for i in range(n-1, -1, -1):
     ...




More information about the Python-list mailing list