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


Groups > comp.lang.python > #2217

Re: Guido rethinking removal of cmp from sort method

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <apardon@vub.ac.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'guido': 0.04; 'received:134': 0.05; 'forcing': 0.07; 'lesser': 0.07; 'terry': 0.07; 'url:bugs': 0.07; 'python': 0.07; ':-).': 0.09; 'cases.': 0.09; 'comparisons': 0.09; 'internally': 0.09; 'referencing': 0.09; 'subject:method': 0.09; 'tracker': 0.09; 'wrote:': 0.14; 'answer,': 0.16; 'arbitrary.': 0.16; 'cmp': 0.16; 'presented,': 0.16; 'py3k': 0.16; 'pydev': 0.16; 'reedy': 0.16; 'rossum': 0.16; 'sorting': 0.16; 'subject:sort': 0.16; 'argument': 0.16; 'case.': 0.16; 'skip:m 30': 0.16; 'code.': 0.18; 'input': 0.18; "wouldn't": 0.18; 'comparing': 0.19; 'functions,': 0.19; 'mapping': 0.19; 'tue,': 0.20; 'code,': 0.20; 'discussion': 0.20; '(which': 0.21; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'values': 0.23; 'conflicts': 0.23; 'translated': 0.23; 'cases': 0.25; 'times,': 0.25; 'compare': 0.26; 'parameters': 0.26; 'times.': 0.26; 'van': 0.27; 'function': 0.27; 'problem': 0.29; 'opposed': 0.29; 'sort': 0.30; 'list': 0.30; 'avoided': 0.31; 'comparison': 0.31; 'whereas': 0.31; 'does': 0.31; 'it.': 0.31; 'fact': 0.31; 'meaning': 0.31; 'anyone': 0.31; 'called': 0.32; 'to:addr:python- list': 0.32; 'done': 0.32; 'asking': 0.32; 'minor': 0.33; 'things': 0.33; 'someone': 0.33; '(for': 0.33; 'using': 0.34; 'decide': 0.34; 'difference': 0.35; 'there': 0.35; 'rule': 0.35; 'print': 0.35; 'header:User-Agent:1': 0.35; 'point': 0.35; 'constant': 0.35; 'list.': 0.35; 'charset:us-ascii': 0.36; 'data': 0.37; 'two': 0.37; 'it?': 0.37; 'case': 0.37; 'url:python': 0.37; 'bigger': 0.38; 'conflict': 0.38; 'consistent': 0.38; 'depend': 0.38; 'faster': 0.38; 'removing': 0.38; 'thread': 0.38; 'user': 0.38; 'but': 0.38; 'reasonable': 0.38; 'url:org': 0.38; 'current': 0.38; 'log': 0.38; 'realize': 0.39; 'somewhat': 0.39; 'set': 0.39; 'to:addr:python.org': 0.39; 'where': 0.39; 'how': 0.39; 'would': 0.40; 'best': 0.60; 'huge': 0.62; '2011': 0.62; 'mar': 0.64; 'play': 0.64; 'engine': 0.67; 'nothing.': 0.68; 'lost': 0.71; 'interested,': 0.75; 'following.': 0.84; 'subject:removal': 0.84; 'increases': 0.91; 'items,': 0.91
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AvsEAGjpkk2GuA9G/2dsb2JhbAClTHeIebRHhWoEjQaDSQ
Date Wed, 30 Mar 2011 11:06:20 +0200
From Antoon Pardon <Antoon.Pardon@rece.vub.ac.be>
To python-list@python.org
Subject Re: Guido rethinking removal of cmp from sort method
References <AANLkTi=Ux2wRJ8u=myd1jeneR+kZiFhtnwDLHm=GtFtV@mail.gmail.com> <mailman.1207.1300985048.1189.python-list@python.org> <4d8bd8a1$0$29977$c3e8da3$5496439d@news.astraweb.com> <mailman.1231.1301044708.1189.python-list@python.org> <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> <imtcab$r3r$1@dough.gmane.org>
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Content-Disposition inline
In-Reply-To <imtcab$r3r$1@dough.gmane.org>
User-Agent Mutt/1.5.20 (2009-06-14)
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9.1301475780.2990.python-list@python.org> (permalink)
Lines 63
NNTP-Posting-Host 82.94.164.166
X-Trace 1301475780 news.xs4all.nl 81484 [::ffff:82.94.164.166]:40904
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:2217

Show key headers only | View raw


On Tue, Mar 29, 2011 at 03:35:40PM -0400, Terry Reedy wrote:
> 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?

I wouldn't have a problem with it.

I would also like to react to the following.

Guido van Rossum in msg95975 on http://bugs.python.org/issue1771 wrote:
| Also, for all of you asking for cmp back, I hope you realize that 
| sorting N values using a custom cmp function makes about N log N calls 
| calls to cmp, whereas using a custom key calls the key function only N 
| times.  This means that even if your cmp function is faster than the 
| best key function you can write, the advantage is lost as N increases 
| (which is just where you'd like it to matter most :-).

This is a play on semantics. If you need python code to compare
two items, then this code will be called N log N times, independently
of the fact how this code is presented, as a cmp function or as rich
comparison methods. So forcing people to write a key function in cases
where this will only result in the cmp code being translated to __lt__
code, accomplishes nothing. 

As far as I can see, key will only produce significant speedups, if
comparing items can then be completly done internally in the python
engine without referencing user python code.

> 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).

My rule of thumb is that a < b is equivallent with cmp(a, b) < 0

> 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.

But what does this have to do with use cases? Does what is reasonable
depend on the current use cases without regard of possible future use
cases? Is the conflict between key and cmp a lesser problem in the
case of someone having a huge data set to sort on a computer that lacks
the resources to decorate as opposed to currently noone having such
a data set? Are we going to decide which functions/methods get a cmp
argument depening on which use cases we currently have that would need it?

This thread started with a request for use cases. But if you take this
kind of things into consideration, I don't see how use cases can then
make a big difference in the final decision.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Guido rethinking removal of cmp from sort method Antoon Pardon <Antoon.Pardon@rece.vub.ac.be> - 2011-03-30 11:06 +0200
  Re: Guido rethinking removal of cmp from sort method Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-03-31 02:13 +0000
    Re: Guido rethinking removal of cmp from sort method Antoon Pardon <Antoon.Pardon@rece.vub.ac.be> - 2011-03-31 11:41 +0200
      Re: Guido rethinking removal of cmp from sort method Paul Rubin <no.email@nospam.invalid> - 2011-03-31 04:59 -0700
    Re: Guido rethinking removal of cmp from sort method geremy condra <debatem1@gmail.com> - 2011-04-01 14:31 -0700
      Re: Guido rethinking removal of cmp from sort method Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-02 00:41 +0000
        Re: Guido rethinking removal of cmp from sort method geremy condra <debatem1@gmail.com> - 2011-04-01 18:22 -0700
          Re: Guido rethinking removal of cmp from sort method Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-02 11:01 +0000
            Re: Guido rethinking removal of cmp from sort method geremy condra <debatem1@gmail.com> - 2011-04-02 23:22 -0700
            Re: Guido rethinking removal of cmp from sort method Brian Quinlan <brian@sweetapp.com> - 2011-04-03 16:34 +1000
              Re: Guido rethinking removal of cmp from sort method Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-03 10:21 +0000
                Re: Guido rethinking removal of cmp from sort method geremy condra <debatem1@gmail.com> - 2011-04-03 12:58 -0700
        Re: Guido rethinking removal of cmp from sort method Paul Rubin <no.email@nospam.invalid> - 2011-04-01 19:29 -0700
          Re: Guido rethinking removal of cmp from sort method Chris Angelico <rosuav@gmail.com> - 2011-04-02 13:43 +1100
          Re: Guido rethinking removal of cmp from sort method Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-04-02 11:27 +0000

csiph-web