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

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Jan 15 11:48:30 EST 2008


Helmut Jarausch:
> The clear winner is
>
> def del_by_key(L,key) :
>    for pos, (k,d) in enumerate(L):
>      if  k == key :
>        del L[pos]
>        break

If you use Psyco this is faster:

def del_by_key(L,key):
   pos = 0
   for pair in L:
     if  pair[0] == key :
       del L[pos]
       break
     pos += 1

Bye,
bearophile



More information about the Python-list mailing list