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 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]

-- 
Neil Cerutti <[EMAIL PROTECTED]>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to