<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
> And yes, NaN is a problem, but it's exactly the same problem it is<br>
> everywhere else in Python.<br>
<br>
I was serious about wanting to know how dictionaries handle NaN as a<br>
key. Is it a special case? The obvious way of implementing it would<br>
conclude it is a hash collision but not a match. I notice that<br>
Decimal('NaN') and float nan don't match each other (as do any other<br>
float/Decimal with the same value) but they do both work as dictionary<br>
keys.<br></blockquote></div><br></div><div class="gmail_extra">NaN is, by definition, never equal to another NaN, which is why the following happens:<br><br>>>> nan = float('NAN')<br>>>> n2 = nan<br>

>>> n2 == nan<br>False<br>>>> n2 is nan<br>True<br><br></div><div class="gmail_extra">It turns out that many other things which I never thought about before can be dictionary keys...<br><br>>>> d = {'a':1, nan: 2}<br>

>>> d[n2]<br>2<br>>>> d[NotImplemented] = 3<br>>>> d[...] = 4<br>>>> d[None] = 5<br>>>> d[True] = 6<br>>>> d[False] = 7<br>>>> d<br>{'a': 1, nan: 2, False: 7, True: 6, NotImplemented: 3, Ellipsis: 4, None: 5}<br>

<br></div></div>