[Baypiggies] list problem

Vikram kpguy at rediffmail.com
Thu Jul 22 15:38:24 CEST 2010


this is exactly what i wanted to do. many thanks.
-Vikram

On Thu, 22 Jul 2010 16:36:51 +0530  wrote
>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 --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100722/741be3c1/attachment.html>


More information about the Baypiggies mailing list