common problem - elegant solution sought
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:
>> 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.
> 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 == 'b':
> del L[i]
unfortunately, they are sorted on 'Date'
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
More information about the Python-list