Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #2188
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Subject | Re: Guido rethinking removal of cmp from sort method |
| Date | 2011-03-29 15:35 -0400 |
| References | (7 earlier) <4d8d1203$0$29977$c3e8da3$5496439d@news.astraweb.com> <mailman.1333.1301315748.1189.python-list@python.org> <4d90ac87$0$30000$c3e8da3$5496439d@news.astraweb.com> <20110329084657.GE26597@trout.vub.ac.be> <AANLkTinyEpTVaAjikP8M108ymj=J6LV2styp+Md-siwj@mail.gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1378.1301427355.1189.python-list@python.org> (permalink) |
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Guido rethinking removal of cmp from sort method Terry Reedy <tjreedy@udel.edu> - 2011-03-29 15:35 -0400
csiph-web