Benchmark [was Re: common problem - elegant solution sought]

Helmut Jarausch jarausch at skynet.be
Tue Jan 15 14:00:36 EST 2008


Paul Rubin wrote:
> Helmut Jarausch <jarausch at skynet.be> writes:
>> def del_by_key(L,key) :
>>    for pos, (k,d) in enumerate(L):
>>      if  k == key :
>>        del L[pos]
>>        break
> 
> This looks very dangerous, mutating L while iterating over it.

No, as Bruno Desthuilliers has pointed out, because one
breaks out of the loop immediately.

Helmut.

-- 
Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany



More information about the Python-list mailing list