sorting a dictionary
Alex Martelli
aleax at aleax.it
Thu Feb 6 05:19:01 EST 2003
Ian Bicking wrote:
...
> It would be better if there was an alternative to < (or cmp) that was
> potentially arbitrary but also stable and would not raise exceptions.
> Like maybe "order".
>
> Then, would an entirely arbitrary function be appropriate? Like:
>
> def order(a, b):
> return cmp(id(a), id(b))
I cannot see any practical use for this -- it seems to give
far too few "guarantees" one could base any use on. E.g.:
>>> def order(a, b):
... return cmp(id(a), id(b))
...
>>> x=11
>>> order(x,11)
0
>>> x=1111
>>> order(x,1111)
1
>>>
How would you use an "ordering" which can see "equality"
for very small integers but not for somewhat-larger ones,
etc, etc?
I think at the very least any ordering should cooperate
with == to the extent that x==y --> order(x,y)==0 (maybe
not the reverse, if the ordering is looking at fewer
aspects of x and y than the equality-comparison is --
but such an ordering wouldn't be suitable for general
use, I think).
Alex
More information about the Python-list
mailing list