[Python-3000] Need closure on __cmp__ removal
Brett Cannon
brett at python.org
Wed Jan 9 20:34:59 CET 2008
On Jan 9, 2008 11:34 AM, Oleg Broytmann <phd at phd.pp.ru> wrote:
> 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)
And don't forget about operator.attrgetter().
-Brett
More information about the Python-3000
mailing list