sorting a dictionary

Mel Wilson mwilson at the-wire.com
Fri Feb 7 11:41:27 EST 2003


In article <gCJ0a.142939$0v.4065958 at news1.tin.it>,
Alex Martelli <aleax at aleax.it> wrote:
>Mel Wilson wrote:
>> def square_peg_vs_round_hole (a, b):
>
>This implementation raises an exception

Hmmm.. even more impending doom than I thought.

>                                        when you try
>to compare (e.g.) lists whose first items are a
>complex and any number respectively (because it falls
>back to cmp for this case and cmp cannot know it
>needs to call square_etc recursively for lexical
>comparisons of sequences).  Reimplementing all of
>cmp is quite a bother...

   It isn't simple to satisfy, at the same time, two groups
who need opposite things.  Maybe the cmp we have, doing the
right thing quite often, and doing something not insane most
of the time, is the most useful kludge we can get.

   I could extend square_peg_... to recurse down lists, but
that way there's the question of what's meant to be discrete
and what's meant to be a list, and we've been there already.
And classes generally -- exactly whose __cmp__ method am
I going to ignore?

   Even worse ideas are:

system.__cmp__ = square_peg_vs_round_hole

because it makes the behaviour of the whole interpreter
depend on the prowess of J. Random Coder (e.g. me) and

pragma no_fault_complex_compares

to micro-mamage cmp behaviour over a code suite.  Bad
because there are a gazillion things that 'need' to be
micro-managed.  Python would immediately cease to be a
simple language.  And the stacking and unstacking...  You
won't see a PEP from me anythime soon.

        Regards.        Mel.




More information about the Python-list mailing list