A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2004-September/048850.html below:

[Python-Dev] PEP 265 - Sorting dicts by value

[Python-Dev] PEP 265 - Sorting dicts by valueNick Coghlan ncoghlan at iinet.net.au
Mon Sep 13 13:46:47 CEST 2004
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.

More information about the Python-Dev mailing list

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