Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: cl@isbd.net Newsgroups: comp.lang.python Subject: Re: How to show a dictionary sorted on a value within its data? Date: Wed, 1 Oct 2014 13:19:51 +0100 Lines: 31 Message-ID: <748tfb-5lu.ln1@chris.zbmc.eu> References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Trace: individual.net 4sNw4AEiYXy+akUUFJ4apAET50xZX9zGBS4ILuzNiSRHfbuws= X-Orig-Path: not-for-mail Cancel-Lock: sha1:KvoDWWpO3LLF6bYyiUztXGjUJ5Q= User-Agent: tin/2.2.0-20131224 ("Lochindaal") (UNIX) (Linux/3.13.0-36-generic (x86_64)) Xref: csiph.com comp.lang.python:78546 Joel Goldstick wrote: > On Wed, Oct 1, 2014 at 5:58 AM, 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? Row is a namedtuple, the dictionary is extracted from a database with a row factory so the namedtuple names are the column names. It means that if I change a column name then most things continue to work without any code changes, and also I can refer to items in the tuple by name of course. I have the answer to my question in other responses. -- Chris Green ยท