wtfpython
wtfpython copied to clipboard
List Equality
>>> 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 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
Right, this one is covered in the nan-reflexivity example,