wtfpython icon indicating copy to clipboard operation
wtfpython copied to clipboard

List Equality

Open MatzeB opened this issue 5 years ago • 2 comments

>>> nan = float("nan")
>>> nan == nan
False
>>> [nan] == [nan]
True

Explanation: In most containers python assumes identical objects must be equal and does not even invoke a comparison function like __eq__.

MatzeB avatar May 02 '20 04:05 MatzeB

@MatzeB as far as I can tell, unfortunately NaN objects generated by float('nan') don't even seem to be identical:

>>> float('nan') is float('nan')
False

I found this great article that analyzes this behavior in detail: https://towardsdatascience.com/navigating-the-hell-of-nans-in-python-71b12558895b

georgepsarakis avatar May 02 '20 14:05 georgepsarakis

Right, this one is covered in the nan-reflexivity example,

image

satwikkansal avatar Aug 01 '20 12:08 satwikkansal