[Python-3000] Need closure on __cmp__ removal

Bill Janssen janssen at parc.com
Wed Jan 9 20:26:52 CET 2008


Steve Bethard writes:
> On Jan 8, 2008 3:55 PM, Brett Cannon <brett at python.org> wrote:
> > On Jan 8, 2008 2:41 PM, Guido van Rossum <guido at python.org> wrote:
> > > list.sort() and built-in sorted() are the least of our problems: even
> > > though the API uses cmp, the implementation actually only ever uses
> > > '<'; and the preferred API is to use the 'key' argument instead of
> > > passing a compare function; that's much more efficient.
> > >
> > > Maybe we should retire the compare function completely in 3.0?
> > >
> >
> > +1 from me. I personally have always hated the whole, -1, 0, 1 style
> > of comparison anyway.
> 
> +1 from here too.  I've found it frustrating that the first argument
> to sort() and sorted() is the least useful. ;-)

I'm a bit baffled here; I find cmp() fairly handy in writing sort
routines:

   newlist = oldlist.sort(lambda v1, v2: cmp(v1.attr_x, v2.attr_x))

Is there a better / newer / official way of doing this?  If not, isn't
"cmp()" still useful to have around?

(Bear in mind that I still use the 2.3.5 dialect of Python as much as
possible, due to the continued widespread deployment of Mac OS X 10.4.
So my style may be out-of-date.)

Bill


More information about the Python-3000 mailing list