Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2188 > unrolled thread

Re: Guido rethinking removal of cmp from sort method

Started byTerry Reedy <tjreedy@udel.edu>
First post2011-03-29 15:35 -0400
Last post2011-03-29 15:35 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Guido rethinking removal of cmp from sort method Terry Reedy <tjreedy@udel.edu> - 2011-03-29 15:35 -0400

#2188 — Re: Guido rethinking removal of cmp from sort method

FromTerry Reedy <tjreedy@udel.edu>
Date2011-03-29 15:35 -0400
SubjectRe: Guido rethinking removal of cmp from sort method
Message-ID<mailman.1378.1301427355.1189.python-list@python.org>
For anyone interested, the tracker discussion on removing cmp is at
http://bugs.python.org/issue1771
There may have been more on the old py3k list and pydev list.

One point made there is that removing cmp= made list.sort consistent 
with all the other comparision functions, 
min/max/nsmallest/nlargest/groupby that only have a key arg. How many 
would really want cmp= added everywhere?

A minor problem problem with cmp is that the mapping between return 
values and input comparisons is somewhat arbitrary. Does -1 mean a<b or 
b<a? (That can be learned and memorized, of course, though I tend to 
forget without constant use).

A bigger problem is that it conflicts with key=. What is the result of
l=[1,3,2]
l.sort(cmp=lambda x,y:y-x, key=lambda x: x)
print l
? (for answer, see http://bugs.python.org/issue11712 )

While that can also be learned, I consider conflicting parameters 
undesireable and better avoided when reasonably possible. So I see this 
thread as a discussion of the meaning of 'reasonably' in this particular 
case.

-- 
Terry Jan Reedy

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web