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


Groups > comp.lang.python > #81905

Re: How is max supposed to work, especially key.

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail
From Jussi Piitulainen <jpiitula@ling.helsinki.fi>
Newsgroups comp.lang.python
Subject Re: How is max supposed to work, especially key.
Date 04 Dec 2014 14:58:00 +0200
Organization A noiseless patient Spider
Lines 31
Sender jpiitula@ruuvi.it.helsinki.fi
Message-ID <qot1tofa7xj.fsf@ruuvi.it.helsinki.fi> (permalink)
References <547760b3$0$6876$e4fe514c@dreader36.news.xs4all.nl> <mailman.16378.1417111312.18130.python-list@python.org> <548032dd$0$15926$e4fe514c@dreader35.news.xs4all.nl> <qotbnnj4rst.fsf@ruuvi.it.helsinki.fi> <54804bb6$0$12988$c3e8da3$5496439d@news.astraweb.com>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx02.eternal-september.org; posting-host="da42b2e96e23bc971f06525f495b78b4"; logging-data="8931"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Yn8jYGdVWTsYPuJJQoA10Kd6kFMLqZ7E="
User-Agent Gnus/5.09 (Gnus v5.9.0) Emacs/21.3
Cancel-Lock sha1:kvGhsu7uiPEZysTHTxiKXHPO6Gs=
Xref csiph.com comp.lang.python:81905

Show key headers only | View raw


Steven D'Aprano writes:
> Jussi Piitulainen wrote:
> 
> > Would you also want sorted called something else when used with a
> > key?  Because it doesn't produce a sorted list of the keys either:
> > 
> >   >>> data = ("short", "long", "average")
> >   >>> sorted(data, key=len)
> >   ['long', 'short', 'average']
> >   >>> max(data, key=len)
> >   'average'
> 
> I agree with the point you are making, but I disagree with the
> wording you use. The result of calling sort() with key=len *is*
> sorted. It is sorted by length of the word.

It's sorted but it's not a list of the keys. That seemed to be a point
of contention about naming max-with-key max: it doesn't return a key.

> Same for calling max() with a key. The result is still the maximum
> value.  The difference is how you decide which of two elements is
> greater:
> 
> max(list_of_foods, key=calories)
> max(list_of_foods, key=weight)
> max(list_of_foods, key=cost)
> 
> That is three different ways to decide which is the maximal food in
> the list: by number of calories, by weight, or by cost.

Yes. I don't see any disagreement between us.

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


Thread

How is max supposed to work, especially key. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-11-27 17:34 +0000
  Re: How is max supposed to work, especially key. Peter Otten <__peter__@web.de> - 2014-11-27 19:01 +0100
    Re: How is max supposed to work, especially key. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-12-04 10:09 +0000
      Re: How is max supposed to work, especially key. Chris Angelico <rosuav@gmail.com> - 2014-12-04 21:18 +1100
        Re: How is max supposed to work, especially key. albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-12-04 10:35 +0000
          Re: How is max supposed to work, especially key. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-12-04 12:51 +0200
          Re: How is max supposed to work, especially key. Peter Otten <__peter__@web.de> - 2014-12-04 12:31 +0100
          Re: How is max supposed to work, especially key. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-04 23:03 +1100
          Re: How is max supposed to work, especially key. Terry Reedy <tjreedy@udel.edu> - 2014-12-04 10:47 -0500
      Re: How is max supposed to work, especially key. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-12-04 12:45 +0200
        Re: How is max supposed to work, especially key. Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-12-04 22:55 +1100
          Re: How is max supposed to work, especially key. Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-12-04 14:58 +0200
      Re: How is max supposed to work, especially key. Peter Otten <__peter__@web.de> - 2014-12-04 12:24 +0100
      Re: How is max supposed to work, especially key. random832@fastmail.us - 2014-12-04 09:09 -0500

csiph-web