[Tutor] Possible with list comprehension?

Stewart Midwinter midtoad at yahoo.com
Mon Dec 25 00:50:37 CET 2006


Aah!  A nested list comprehension.  I hadn't considered that. Thanks, your solution is both concise and easy to read. 

and, oops, you're right, I was thinking of median but saying mean. 

cheers
S

----- Original Message ----
From: Kent Johnson <kent37 at tds.net>

That is the median, not the mean. For this approach to work you have to 
sort dataDict.items(), in general dict keys and values are not in any 
obvious order. Fortunately it is easy to do this:
prods = [ key for key,val in sorted(dataDict.items()) for i in range(val) ]






__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the Tutor mailing list