can't sort

Anders J. Munch andersjm at dancontrol.dk
Mon May 26 04:38:47 EDT 2003


"andrew cooke" wrote:
> "Anders J. Munch" <andersjm at dancontrol.dk> writes:
> > def sort(sequence, cmpfunc=None, project=None):
> 
> are you looking for comments on this particular code, or is it just a
> general example?  

This particular code.  There's some talk though about switching to
less-than predicates instead of -1,0,1 compares in future Pythons, so
I'd have take that into account before nominating anything my final
candidate.

I suppose I should write a PEP.  Or are simple library additions below
the PEP radar?

>i don't know whether it should be included in python
> or not, but if it was, i'd expect to be able to use cmpfunc and
> project together.  also, what is the rank ("no") used for?  stability?

It has that effect too, but mainly it's to avoid comparing 'val' for
those 'project(val)' that happen to be equal.

cmfunc+project doesn't give you the speed gains of the DSU, so you may
as well integrate the projection into cmpfunc.  Still, for
completeness, and for those rare cases where the projection function
itself is expensive, I guess the restriction should be lifted so you
can use them together.

- Anders






More information about the Python-list mailing list