On 29 May 2011 10:16, Erik Max Francis <m...@alcyone.com> wrote:

> MRAB wrote:
>
>> Here's a curiosity. float("nan") can occur multiple times in a set or as a
>> key in a dict:
>>
>>  >>> {float("nan"), float("nan")}
>> {nan, nan}
>>
>> except that sometimes it can't:
>>
>>  >>> nan = float("nan")
>>  >>> {nan, nan}
>> {nan}
>>
>
> 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.
>
>
> >>> nan = float("nan")
> >>> nan == nan
> False
>
> In short, don't do that.


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.

Tim Delaney
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to