bisect on a list of lists

bearophileHUGS at bearophileHUGS at
Fri Mar 9 22:59:16 CET 2007

Paulo da Silva:
> What is the best way to have something like the bisect_left
> method on a list of lists being the comparision based on an
> specified arbitrary i_th element of each list element?

You may use this recipe of mine that I've just put there for you, but
it's not fully tested yet (if you spot problems I'm willing to fix

Or you can create a little class, that wraps your list with just a
__cmp__ method that works on the n-th element of the list. Then you
can use heapq on many instances of that class created with a list

Probably there are other solutions too.


More information about the Python-list mailing list