Quant Memo
Coding/●●●●●

The value that is not equal to itself: handling NaN

A feed occasionally emits a NaN (from a 0.0/0.0 in a ratio). A teammate is baffled:

>>> x = float("nan")
>>> x == x
False
>>> sorted([3.0, x, 1.0, 2.0])
[3.0, nan, 1.0, 2.0]      # not sorted!

Explain why NaN != NaN and why the sort came out scrambled, then write a clean_and_max(values) that drops NaNs and returns the maximum safely.

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions