2015-12-21 03:05:20 +00:00
|
|
|
nan As Key
|
|
|
|
^^^^^^^^^^
|
|
|
|
|
|
|
|
`In CPython <http://doc.pypy.org/en/latest/cpython_differences.html>`_,
|
|
|
|
nan is especially tricky when used as a dictionary key::
|
|
|
|
|
|
|
|
>>> d = {float('nan'): 'nan'}
|
|
|
|
>>> d
|
|
|
|
{nan: 'nan'}
|
|
|
|
>>> d[float('nan')] # doctest: +SKIP
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
KeyError: nan
|
|
|
|
>>> d[float('nan')] = 'not overwritten'
|
|
|
|
>>> d # doctest: +SKIP
|
|
|
|
{nan: 'nan', nan: 'not overwritten'}
|
|
|
|
|
|
|
|
In other Python implementations such as PyPy,
|
|
|
|
nan behaves just like any other dictionary key.
|
2016-06-28 04:05:22 +00:00
|
|
|
But in CPython, beware of this unexpected behavior,
|
|
|
|
which applies to bidicts too.
|
|
|
|
bidict contains no special-case logic
|
|
|
|
for dealing with nan as a key,
|
|
|
|
so the behavior will match dict's in the host environment.
|