[Python-ideas] `OrderedDict.sort`

random832 at fastmail.us random832 at fastmail.us
Wed Sep 25 15:47:18 CEST 2013

On Tue, Sep 24, 2013, at 23:27, Andrew Barnert wrote:
> Yes, every key must be comparable with every other key, and the
> comparison must define a strict weak order, and the keys must be
> comparison-immutable, and there's no way to test either of those
> automatically. By comparison, a dict needs hashable keys, which can be
> tested automatically, and equality-immutable and hash-immutable keys,
> which can't really be tested but in practice hash is an acceptable test.

I think of this as part of the hashable protocol, whereas we know that
lists are orderable despite being mutable.

> But it's no worse than many other requirements in the stdlib that can't
> be tested automatically.
> And yes, NaN is a problem, but it's exactly the same problem it is
> everywhere else in Python.

I was serious about wanting to know how dictionaries handle NaN as a
key. Is it a special case? The obvious way of implementing it would
conclude it is a hash collision but not a match. I notice that
Decimal('NaN') and float nan don't match each other (as do any other
float/Decimal with the same value) but they do both work as dictionary

More information about the Python-ideas mailing list