[Python-ideas] `OrderedDict.sort`

Oscar Benjamin oscar.j.benjamin at gmail.com
Wed Sep 25 15:53:43 CEST 2013

On 25 September 2013 14:47,  <random832 at fastmail.us> wrote:
>> 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
> keys.

They're effectively compared by identity:

>>> {float('nan'), float('nan')}
set([nan, nan])
>>> a = float('nan')
>>> {a, a}


More information about the Python-ideas mailing list