Guido rethinking removal of cmp from sort method

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 14 22:14:28 EDT 2011


On Mon, 14 Mar 2011 23:37:06 +0000, Nobody wrote:

> On Mon, 14 Mar 2011 12:39:35 -0700, Paul Rubin wrote:
> 
>> Finally I concocted an "infinite" example which we agreed is
>> artificial: you are given a list of generators denoting real numbers,
>> for example pi generates the infinite sequence 3,1,4,1,5,9... while e
>> generates 2,7,1,8,...  You can sort these with cmp but not with key.
> 
> Is there some restriction on the return type of the key= function? If
> not, you can define a class with appropriate comparison methods and have
> key= return instances of that class.

You mean like this?

http://docs.python.org/dev/library/functools.html#functools.cmp_to_key




-- 
Steven



More information about the Python-list mailing list