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

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to