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


Groups > comp.lang.python > #78536

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'output': 0.05; 'item.': 0.09; 'parameter': 0.09; 'subject:How': 0.10; 'cc:addr:python- list': 0.11; 'cmp=': 0.16; 'function?': 0.16; 'sorted()': 0.16; 'subject:show': 0.16; 'tuple': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'sort': 0.25; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; '???': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'quite': 0.32; 'url:python': 0.33; 'maybe': 0.34; 'skip:d 20': 0.34; "can't": 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'subject:data': 0.36; 'url:listinfo': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'e.g.': 0.38; 'needed': 0.38; 'skip:p 20': 0.39; 'url:mail': 0.40; 'skip:u 10': 0.60; 'read': 0.60; 'here:': 0.62; 'skip:n 10': 0.64; 'joel': 0.91; 'to:none': 0.92
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:content-transfer-encoding; bh=R5gt7D2Yk8dLylfkPYs9xwOqOqC8VM2Q/aYmjt3o3z8=; b=PY++u0PdbUpzupJ5HKVXDqqigMD1/592kTf2Y7eMGg2GXcJVkqp3MgePXh6IOHhM2z uRL8lkkyyRgG8Nfk5nht4li4kRmn6fQ45Wg/2NK517VPG25+vpln0Z58HIoRXoGc+h4X al0+q3i+/X3ixzCIpOmaLAdrfKjhw91WIpbaQGYH2Knjos//3tb3XzuKYnr89ih5mY8I 0n++Q9J375Pk7syPBn92kQqmTJbeZui9zCP+MOKnxz97gGuiIRj0vDIF4pol1FSgTbdY CmHziOx+sCbR+4yOJ3DlJ8jP9PcksORUop8B0oP5My22hu7JyIXIw7Vt5/lv4lm2/i9t KF6w==
MIME-Version 1.0
X-Received by 10.224.136.200 with SMTP id s8mr72487230qat.44.1412159871941; Wed, 01 Oct 2014 03:37:51 -0700 (PDT)
In-Reply-To <crvsfb-drf.ln1@chris.zbmc.eu>
References <crvsfb-drf.ln1@chris.zbmc.eu>
Date Wed, 1 Oct 2014 06:37:51 -0400
Subject Re: How to show a dictionary sorted on a value within its data?
From Joel Goldstick <joel.goldstick@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
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.14514.1412159881.18130.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1412159881 news.xs4all.nl 2950 [2001:888:2000:d::a6]:60364
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:78536

Show key headers only | View raw


On Wed, Oct 1, 2014 at 5:58 AM,  <cl@isbd.net> wrote:
> I have a dictionary as follows:-
>
> {
> u'StarterAmps1': Row(id=4, ain=u'AIN3', name=u'StarterAmps1', conv=6834.374834509803, Description=u'Starter Amps'),
> u'LeisureVolts': Row(id=1, ain=u'AIN0', name=u'LeisureVolts', conv=29.01374215995874, Description=u'Leisure Volts'),
> u'RudderPos': Row(id=6, ain=u'AIN5', name=u'RudderPos', conv=0.028125, Description=u'Rudder Position'),
> u'xx': Row(id=7, ain=u'AIN6', name=u'xx', conv=0.028125, Description=u''),
> u'LeisureAmps1': Row(id=3, ain=u'AIN2', name=u'LeisureAmps1', conv=32.727273081945, Description=u'Leisure Amps'),
> u'StarterVolts': Row(id=2, ain=u'AIN1', name=u'StarterVolts', conv=28.94469628911757, Description=u'Starter Volts')
> }

Is Row a function?  Or do you have a key with a tuple as the value?
>
> I want to output a menu to a user comprising some parts of the
> dictionary (ain and Description) sorted by ain.
>
> Is there some incantation of sorted() that will do what I want?  I
> can't quite fathom out the 'key=' parameter needed to sort it by the
> tuple item.  Maybe I need a cmp= ?
>
> E.g. I want to do something like:-
>
>     for meas in sorted(adc.cfg, key=???):
>         print(adc.cfg[meas].ain, adc.cfg[meas].Description)
>
> What's needed in the ???
>
> --
> Chris Green
> ยท

You might read here:
http://www.pythoncentral.io/how-to-sort-python-dictionaries-by-key-or-value/
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com

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