Re: bisect on a list of lists

2007-03-09 Thread Gabriel Genellina
En Sat, 10 Mar 2007 01:23:11 -0300, Paulo da Silva <[EMAIL PROTECTED]> escribió: > Gabriel Genellina escreveu: > >> Just omit the __init__ method, if you don't have anything additional to >> do. The inherited method will be used instead, as always: > > > Then, if I have something additional, I c

Re: bisect on a list of lists

2007-03-09 Thread Paulo da Silva
Gabriel Genellina escreveu: ... > Just omit the __init__ method, if you don't have anything additional to > do. The inherited method will be used instead, as always: Then, if I have something additional, I can do def __init__(self,l=None): if l!=None:

Re: bisect on a list of lists

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 23:45:50 -0300, Steven D'Aprano <[EMAIL PROTECTED]> escribió: > On Fri, 09 Mar 2007 18:57:42 -0300, Gabriel Genellina wrote: > >> En Fri, 09 Mar 2007 17:15:44 -0300, Paulo da Silva >> <[EMAIL PROTECTED]> escribió: >> >>> What is the best way to have something like the bisect_

Re: bisect on a list of lists

2007-03-09 Thread Steven D'Aprano
On Fri, 09 Mar 2007 18:57:42 -0300, Gabriel Genellina wrote: > En Fri, 09 Mar 2007 17:15:44 -0300, Paulo da Silva > <[EMAIL PROTECTED]> escribió: > >> 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 arbitrar

Re: bisect on a list of lists

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 21:25:24 -0300, Paulo da Silva <[EMAIL PROTECTED]> escribió: > Thanks Gabriel. This sounds very nice for my purpose. > I have some doubts however. How do I "transform" a list into > MyList? Is this the best way? > > class MyList(list): > def __init__(self,l=None): >

Re: bisect on a list of lists

2007-03-09 Thread Paulo da Silva
Gabriel Genellina escreveu: > En Fri, 09 Mar 2007 17:15:44 -0300, Paulo da Silva > <[EMAIL PROTECTED]> escribió: ... > > lists *are* classes (at least since Python 2.2) > Inherit from the builtin list, redefine __cmp__(self, other) as ... Thanks Gabriel. This sounds very nice for my purpose. I h

Re: bisect on a list of lists

2007-03-09 Thread Peter Otten
Paulo da Silva wrote: > 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? A simple way that leaves the lists untouched: >>> import bisect, random >>> from operator imp

Re: bisect on a list of lists

2007-03-09 Thread bearophileHUGS
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 y

Re: bisect on a list of lists

2007-03-09 Thread Gabriel Genellina
En Fri, 09 Mar 2007 17:15:44 -0300, Paulo da Silva <[EMAIL PROTECTED]> escribió: > 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? > > Is there, for lists, something

bisect on a list of lists

2007-03-09 Thread Paulo da Silva
Hi! 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? Is there, for lists, something equivalent to the __cmp__ function for classes? Thanks. -- http://mail.python.org/mai