[Python-Dev] Propose to reject PEP 265 -- Sorting Dictionaries by Value

Raymond Hettinger raymond.hettinger at verizon.net
Fri Jun 17 03:03:57 CEST 2005


May I suggest rejecting PEP 265.

As of Py2.4, its use case is easily solved with:

>>> sorted(d.iteritems(), key=itemgetter(1), reverse=True)
[('b', 23), ('d', 17), ('c', 5), ('a', 2), ('e', 1)]

Further, Py2.5 offers a parallel solution to the more likely use case of
wanting the access only the largest counts:

>>> nlargest(2, d.iteritems(), itemgetter(1))
[('b', 23), ('d', 17)]


Raymond



More information about the Python-Dev mailing list