searching a list of tuples

Jason Orendorff jason at
Wed Feb 13 16:30:51 EST 2002

Marcus Stojek writes:
> I have a (huge) list of tuples :
> list=(float 1,float 2,float 3,int).
> The list has been sorted with list.sort()
> Now I have to slice the list in a way
> that:
>   a <= float 1 <= b

Well, on my computer I can make a float that
represents "infinity".  So this works:

import bisect

INF = 1e600
left = bisect.bisect_right(mylist, (a, -INF, -INF, -INF))
right = bisect.bisect_left(mylist, (b, INF, INF, INF))
myslice = mylist[left:right]

## Jason Orendorff

More information about the Python-list mailing list