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


Groups > comp.lang.python > #78643

Re: How to show a dictionary sorted on a value within its data?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'languages,': 0.04; 'args': 0.07; 'discard': 0.07; 'odd': 0.07; 'feature.': 0.09; 'sure,': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'args,': 0.16; 'comp': 0.16; 'effect,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:show': 0.16; 'wrote:': 0.18; 'things.': 0.19; 'programming': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; "aren't": 0.24; 'convenient': 0.24; 'looks': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'equivalent': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'generally': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'values.': 0.31; 'yields': 0.31; 'probably': 0.32; 'call.': 0.33; 'entirely': 0.33; 'fri,': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'subject:data': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'example,': 0.37; 'list': 0.37; 'needed': 0.38; 'list,': 0.38; 'pm,': 0.38; 'short': 0.38; 'functional': 0.39; 'sure': 0.39; 'skip:p 20': 0.39; 'no.': 0.61; 'simple': 0.61; 'times': 0.62; 'map': 0.64; 'places': 0.64; 'abuse.': 0.84; 'technically': 0.84; 'to:none': 0.92; 'hand,': 0.93; 'imagine': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=0UILFyqJRjj26F7QqYji3R3O2aIj2mE0Tmi0RPntgu8=; b=NI/md54sf4g1oBDn3hnFLWVp6DtG4zjSpb7MXXhRCGirHjYp4ktXO1d8hGrSfvHotL d9vy+E9Ufwk9RHDOmH51K93WsdM1v7D/+/c3eDwLNe/8SzGz6SZ+wZVgiP3DBQxnVo3S PUd6nz8BF4sQjwfkvaFFEcmU7IoImwHQ+TFPVTjZwlJZ7Ay8JDuVnWAcWOQ1t7ko8+/S Qpd6PUB2kTaz8DMr3BlQbj7XJbbf5HJo3kl7YYWHIap2oJD7oAId9rjlCkufnAH/uz+v c1l0YK23P902NUcYDva3u9tONF6iWFLTZT4dur/t405UFB6ABvJYM+0Q3jDFPUn0/CJQ 6Dxg==
MIME-Version 1.0
X-Received by 10.42.92.129 with SMTP id t1mr10720958icm.59.1412323791183; Fri, 03 Oct 2014 01:09:51 -0700 (PDT)
In-Reply-To <542e5677$0$2916$c3e8da3$76491128@news.astraweb.com>
References <crvsfb-drf.ln1@chris.zbmc.eu> <mailman.14512.1412159108.18130.python-list@python.org> <cj2tfb-80s.ln1@chris.zbmc.eu> <m0gnj8$6f2$1@ger.gmane.org> <mailman.14539.1412225868.18130.python-list@python.org> <h5jvfb-2cn.ln1@chris.zbmc.eu> <m0jm43$pee$1@reader1.panix.com> <gcb0gb-d2u.ln1@chris.zbmc.eu> <CALwzid=zLF1bUcJ9U31YJJjQ4gRTjE2NGFe8Pv5FwgprpazrGA@mail.gmail.com> <mailman.14564.1412280412.18130.python-list@python.org> <542ddce8$0$12985$c3e8da3$5496439d@news.astraweb.com> <mailman.14568.1412304280.18130.python-list@python.org> <542e5677$0$2916$c3e8da3$76491128@news.astraweb.com>
Date Fri, 3 Oct 2014 18:09:50 +1000
Subject Re: How to show a dictionary sorted on a value within its data?
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.14572.1412323799.18130.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412323799 news.xs4all.nl 2901 [2001:888:2000:d::a6]:55390
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78643

Show key headers only | View raw


On Fri, Oct 3, 2014 at 5:55 PM, Steven D'Aprano <steve@pearwood.info> wrote:
>> which return non-list iterables. There's no really convenient equivalent
>> to the map() usage of "call this function with each of these args, and
>> discard the return values", as it looks very odd to do a list comp for
>> nothing:
>
> map doesn't discard the return values. It accumulates them in a list, or
> yields them in a list comp.

Sure, but I've seen it used in various places to call functions where
you don't care about the return values. Technically it's identical to
the list comp, but somehow it's seen as less of an abuse.

>> Short of borrowing Pike's automap syntax:
>>
>> print(list_of_strings[*])
>
> you mean something like this perhaps?
>
> print(*list_of_strings, sep='\n')

Well, no. In that one specific example, it happens to be possible to
pass all the args to one print() call and get the same effect, but
imagine some function that doesn't have that particular feature. (I
just used print for simplicity.)

>> there's really not much that's better than the original map() call. On
>> the other hand, there aren't actually all that many times when I've
>> needed to do this, and the simple for loop generally suffices:
>>
>> for x in list_of_strings: print(x)
>
> Exactly.

Yeah. That's the normal way to do things. I'm not entirely sure why I
keep seeing map() for that; there's probably a justification in
functional programming languages, or something.

ChrisA

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


Thread

How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-01 10:58 +0100
  Re: How to show a dictionary sorted on a value within its data? Peter Otten <__peter__@web.de> - 2014-10-01 12:24 +0200
    Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-01 11:45 +0100
      Re: How to show a dictionary sorted on a value within its data? Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-01 06:56 -0400
        Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-01 13:16 +0100
      Re: How to show a dictionary sorted on a value within its data? Peter Otten <__peter__@web.de> - 2014-10-01 13:12 +0200
      Re: How to show a dictionary sorted on a value within its data? Travis Griggs <travisgriggs@gmail.com> - 2014-10-01 21:57 -0700
        Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-02 10:40 +0100
          Re: How to show a dictionary sorted on a value within its data? Marko Rauhamaa <marko@pacujo.net> - 2014-10-02 14:17 +0300
            Re: How to show a dictionary sorted on a value within its data? Rustom Mody <rustompmody@gmail.com> - 2014-10-02 10:46 -0700
          Re: How to show a dictionary sorted on a value within its data? Grant Edwards <invalid@invalid.invalid> - 2014-10-02 14:05 +0000
            Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-02 17:33 +0100
              Re: How to show a dictionary sorted on a value within its data? Ian Kelly <ian.g.kelly@gmail.com> - 2014-10-02 13:15 -0600
              Re: How to show a dictionary sorted on a value within its data? Grant Edwards <invalid@invalid.invalid> - 2014-10-02 19:36 +0000
              Re: How to show a dictionary sorted on a value within its data? Dan Stromberg <drsalists@gmail.com> - 2014-10-02 13:06 -0700
                Re: How to show a dictionary sorted on a value within its data? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-03 09:16 +1000
                Re: How to show a dictionary sorted on a value within its data? Chris Angelico <rosuav@gmail.com> - 2014-10-03 12:44 +1000
                Re: How to show a dictionary sorted on a value within its data? Steven D'Aprano <steve@pearwood.info> - 2014-10-03 07:55 +0000
                Re: How to show a dictionary sorted on a value within its data? Chris Angelico <rosuav@gmail.com> - 2014-10-03 18:09 +1000
              Re: How to show a dictionary sorted on a value within its data? Chris Angelico <rosuav@gmail.com> - 2014-10-03 07:01 +1000
  Re: How to show a dictionary sorted on a value within its data? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-01 11:27 +0100
  Re: How to show a dictionary sorted on a value within its data? Joel Goldstick <joel.goldstick@gmail.com> - 2014-10-01 06:37 -0400
    Re: How to show a dictionary sorted on a value within its data? cl@isbd.net - 2014-10-01 13:19 +0100

csiph-web