Moore, Paul wrote: > From: Nick Coghlan > >>In Python 2.4: >> >>->>> ud = dict(a=1, b=2, c=3) >>->>> from operator import itemgetter >>->>> print sorted(ud.items(), key=itemgetter(1), reverse=True) >>[('c', 3), ('b', 2), ('a', 1)] > > > If you haven't done so already, I think this should be submitted > to the cookbook. It's a nice idiom, and demonstrates some useful > Python 2.4 features, and how they work well in combination. It's submitted now. I have a feeling Raymond is the one who should get the credit for the approach, though. I'd be surprised if he made it through the discussions about the introduction of sorted without using this example at least once :) Cheers, Nick.
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