[Python-Dev] PEP 265 - Sorting Dictionaries by Value

Grant Griffin grant.griffin@iowegian.com
Wed, 22 Aug 2001 21:47:56 -0500

At 10:15 AM 8/22/2001 -0400, Guido van Rossum wrote:

> > However, the problem I see with a class-based approach is that this
> > is such a small thing that I'm not even sure how to write a class
> > for it that isn't more grandiose than it deserves.
>Believe me, adding a new method to a heavily-used built-in object is
>much more grandiose than adding a library module.  In addition to "15
>lines of code" we need to update the documentation, add a few lines to
>the test suite, add code to Jython mimicking the feature; 30 books
>will be a little more out of date, and so on.

I guess I don't see how this one is different from any other feature change 
to Python in that regard: they all require code, tests, and docs.

The only real logistical advantage I can see for implementing it as module 
is that the port to Jython would be virtually free. Aside from that, it 
seems like adding a new module (in any form) would cause much _more_ bloat 
overall in terms of SLOCs, tests and documentation.  For example, a new 
library module would get a doc page of its own, but a single new Boolean 
parameter added to items() could be documented by a footnote on the 
"Mapping Types" page, e.g., "If the 'values_first' parameter is set to 
true, the item tuples returned are in (value, key) order rather than the 
default (key, value) order."

The test suite for the new parameter could be just a line or two which 
would compare the values-first items of a test dictionary to the expected 

So, in total, my preferred suggestion, "items(values_first=0)", (which 
actually isn't a _new_ method!) would cause bloat on the order of:

         15 lines of C (and Java)
         1 sentence of documentation
         3 lines of test code

and best of all!:

         0 __future__ statements

And as for making 30 books a little more out of date...well...if Tim 
O'Reilly doesn't give me a big wet kiss for that, I'm gonna demand he 
refund the $54.95 I just paid for the Second Edition of "Programming 
Python" <wink>.