<div class="gmail_quote">On 29 May 2011 10:16, Erik Max Francis <span dir="ltr"><<a href="mailto:max@alcyone.com">max@alcyone.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">MRAB wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Here's a curiosity. float("nan") can occur multiple times in a set or as a key in a dict:<br>
<br>
 >>> {float("nan"), float("nan")}<br>
{nan, nan}<br>
<br>
except that sometimes it can't:<br>
<br>
 >>> nan = float("nan")<br>
 >>> {nan, nan}<br>
{nan}<br>
</blockquote>
<br></div>
It's fundamentally because NaN is not equal to itself, by design. Dictionaries and sets rely on equality to test for uniqueness of keys or elements.<div class="im"><br>
<br>
>>> nan = float("nan")<br>
>>> nan == nan<br></div>
False<br>
<br>
In short, don't do that.</blockquote><div> </div><div>There's a second part the mystery - sets and dictionaries (and I think lists) assume that identify implies equality (hence the second result). This was recently discussed on python-dev, and the decision was to leave things as-is.</div>
<div><br></div><div>Tim Delaney</div></div>