[Baypiggies] list problem

Brian Harring ferringb at gmail.com
Thu Jul 22 13:07:01 CEST 2010


On Thu, Jul 22, 2010 at 09:53:46AM -0000, Vikram  wrote:
>    Suppose you have the following list:
>    >>> x =[['cat',10],['cat',20],['cat',30],['dog',5],['dog',1],['dog',3]]
>    My problem is that i wish to obtain the following two dictionaries:
>    xdictstart = {'cat':10, 'dog':1}
>    xdictend = {'cat':30, 'dog':5}
>    Any nice way to do the above? Thanks.

Think you'd be better off stating the var names as min/max there, 
since that _seems_ to be what you want.  Could be wrong though.  

Suspect your main problem is you're not cheating enough in trying to 
solve it ;)

xdictmin = dict(sorted(x, reverse=True))
xdictmax = dict(sorted(x))

~brian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100722/fcc040ff/attachment.pgp>


More information about the Baypiggies mailing list