Q: sort's key and cmp parameters

Paul Rubin http
Fri Oct 2 22:49:34 CEST 2009

Scott David Daniels <Scott.Daniels at Acm.Org> writes:
> Most cases are moreeasily done with key, and it is
> a good idea to make the most accessible way to a sort be the most
> efficient one.  In the rare case that you really want each comparison,
> the cmp-injection function will do nicely (and can be written as a
> recipe.

I don't think wrapping the sorted objects in an otherwise useless
special purpose class is "nicely", either from a performance or from a
code verbosity point of view.  I avoid Java and its useless extra
classes for a reason ;-).

> In short, make the easy path the fast path, and more will use it;
> provide two ways, and the first that springs to mind is the one
> used.

I think we are saying the same thing.  Python 2.x provides two ways
and you can use whichever one fits the application better.  I have
never understood why Python 3.x finds it necessary to break one of
them.  Maybe I can migrate to Haskell by the time Python 2.x becomes

More information about the Python-list mailing list