common problem - elegant solution sought

Helmut Jarausch jarausch at skynet.be
Tue Jan 15 15:55:23 CET 2008


Neil Cerutti wrote:
> On Jan 15, 2008 5:33 AM, Helmut Jarausch <jarausch at igpm.rwth-aachen.de> 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.
>>
>> My straight forward solution is a bit lengthy, e.g.
>>
>> L=[("a","070501"),("b","080115"),("c","071231")]
> 
> If the data is truly sorted by Unique_ID, then binary search may be
> feasible (though not actually recommended for such small list).
> 
> import bisect
> 
> i = bisect.bisect_left(L, ('b', '000000'))
> if i[0] == 'b':
>     del L[i]
> 

Thanks,
unfortunately, they are sorted on 'Date'
Helmut.


-- 
Helmut Jarausch

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



More information about the Python-list mailing list