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

2008-01-15 Thread [EMAIL PROTECTED]
On Jan 15, 6:18 pm, Paul Rubin wrote: > Helmut Jarausch <[EMAIL PROTECTED]> 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

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

2008-01-15 Thread Helmut Jarausch
Paul Rubin wrote: > Helmut Jarausch <[EMAIL PROTECTED]> 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 ou

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

2008-01-15 Thread Paul Rubin
Helmut Jarausch <[EMAIL PROTECTED]> 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. -- http://mail.python.org/mailman/listinfo/python-list

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

2008-01-15 Thread bearophileHUGS
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]

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

2008-01-15 Thread Helmut Jarausch
Again, many thanks to all who provide their solution. I have timed these (though on my old P3(0.9GHz)) - see below Helmut. Helmut Jarausch wrote: > Hi, > > I'm looking for an elegant solution of the following tiny but common > problem. > > I have a list of tuples (Unique_ID,Date) both of which

Re: common problem - elegant solution sought

2008-01-15 Thread Helmut Jarausch
Neil Cerutti wrote: > On Jan 15, 2008 5:33 AM, Helmut Jarausch <[EMAIL PROTECTED]> wrote: >> Hi, >> >> I'm looking for an elegant solution of the following tiny but common problem. >> >> I have a list of tuples (Unique_ID,Date) both of which are strings. >> I want to delete the tuple (element) wit

Re: common problem - elegant solution sought

2008-01-15 Thread Neil Cerutti
On Jan 15, 2008 5:33 AM, Helmut Jarausch <[EMAIL PROTECTED]> wrote: > Hi, > > I'm looking for an elegant solution of the following tiny but common problem. > > I have a list of tuples (Unique_ID,Date) both of which are strings. > I want to delete the tuple (element) with a given Unique_ID, but > I

Re: common problem - elegant solution sought

2008-01-15 Thread Steven D'Aprano
On Tue, 15 Jan 2008 11:33:36 +0100, Helmut Jarausch wrote: > Hi, > > I'm looking for an elegant solution of the following tiny but common > problem. > > I have a list of tuples (Unique_ID,Date) both of which are strings. I > want to delete the tuple (element) with a given Unique_ID, but I don't

Re: common problem - elegant solution sought

2008-01-15 Thread Helmut Jarausch
Thanks to you all for your help. The solution to regenerate the list skipping the one to be deleted is fine for me since my lists are of moderate size and the operation is infrequent. Helmut. -- Helmut Jarausch Lehrstuhl fuer Numerische Mathematik RWTH - Aachen University D 52056 Aachen, Germ

Re: common problem - elegant solution sought

2008-01-15 Thread Bruno Desthuilliers
Helmut Jarausch a écrit : > Hi, > > I'm looking for an elegant solution of the following tiny but common > problem. > > I have a list of tuples (Unique_ID,Date) both of which are strings. > I want to delete the tuple (element) with a given Unique_ID, but > I don't known the corresponding Date.

Re: common problem - elegant solution sought

2008-01-15 Thread Diez B. Roggisch
Helmut Jarausch wrote: > Hi, > > I'm looking for an elegant solution of the following tiny but common > problem. > > I have a list of tuples (Unique_ID,Date) both of which are strings. > I want to delete the tuple (element) with a given Unique_ID, but > I don't known the corresponding Date. >

Re: common problem - elegant solution sought

2008-01-15 Thread Tim Golden
Helmut Jarausch wrote: > I'm looking for an elegant solution of the following tiny but common problem. > > I have a list of tuples (Unique_ID,Date) both of which are strings. > I want to delete the tuple (element) with a given Unique_ID, but > I don't known the corresponding Date. > > My straigh

Re: common problem - elegant solution sought

2008-01-15 Thread cokofreedom
> I have a list of tuples (Unique_ID,Date) both of which are strings. > I want to delete the tuple (element) with a given Unique_ID, but > I don't known the corresponding Date. > > My straight forward solution is a bit lengthy, e.g. > > L=[("a","070501"),("b","080115"),("c","071231")] Do they hav