[Python-3000] Need closure on __cmp__ removal

Oleg Broytmann phd at phd.pp.ru
Wed Jan 9 20:34:28 CET 2008


On Wed, Jan 09, 2008 at 11:26:52AM -0800, Bill Janssen wrote:
> 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?

   newlist = oldlist.sort(key=lambda v: v.attr_x)

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-3000 mailing list