Bengt Richter wrote:

> or tell sorted what to do ;-)
> 
> >>> original= {
>  ... 'hello':135,
>  ... 'goodbye':30,
>  ... 'lucy':4,
>  ... 'sky':55,
>  ... 'diamonds':239843,
>  ... 'yesterday':4 }
> >>> list(sorted(original.iteritems(), None, lambda t:t[1], True))
>  [('diamonds', 239843), ('hello', 135), ('sky', 55), ('goodbye', 30),
>  ('yesterday', 4), ('lucy',4)] 

or a slight variation on this theme which just gives you the keys in value 
order rather than the tuples:

>>> for k in sorted(original, key=original.get, reverse=True):
        print k, original[k]

        
diamonds 239843
hello 135
sky 55
goodbye 30
yesterday 4
lucy 4
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to