logoalt Hacker News

munchlertoday at 8:41 PM1 replyview on HN

    >>> my_dict[nan] = 3
    >>> my_dict[nan]
    3
Wait, how does that work if nan isn't equal to itself?

Replies

gravel7623today at 8:45 PM

I guess because the hash of an instance stays consistent (which is used to retrieve the value from the dict). The `__eq__` method must disregard the hash and return False for all nans.

show 1 reply