On 17 Sep 2005 11:01:41 GMT, Duncan Booth <duncan.booth at invalid.invalid> wrote: >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] > Nice. I like the keyword usage too. Much clearer than my hastypaste ;-) > >diamonds 239843 >hello 135 >sky 55 >goodbye 30 >yesterday 4 >lucy 4 Regards, Bengt Richter
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4