title: Comparing lists containing NaNs
body: <p>I am trying to compare two different lists to see if they are equal, and was going to remove NaNs, only to discover that my list comparisons still work, despite <code>NaN == NaN -&gt; False</code>. </p>
  
  <p>Could someone explain why the following evaluate <code>True</code> or <code>False</code>, as I am finding this behavior unexpected. Thanks,</p>
  
  <p>I have read the following which don't seem to resolve the issue:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/20320022/why-in-numpy-nan-nan-is-false-while-nan-in-nan-is-true">Why in numpy <code>nan == nan</code> is False while nan in [nan] is True?</a></li>
  <li><a href="https://stackoverflow.com/questions/10034149/why-is-nan-not-equal-to-nan">Why is NaN not equal to NaN? [duplicate]</a></li>
  </ul>
  
  <p>(Python 2.7.3, numpy-1.9.2)</p>
  
  <p><strong>I have marked surprising evaluations with a <code>*</code> at the end</strong></p>
  
  <pre><code>&gt;&gt;&gt; nan = np.nan
  &gt;&gt;&gt; [1,2,3]==[3]
  False
  &gt;&gt;&gt; [1,2,3]==[1,2,3]
  True
  &gt;&gt;&gt; [1,2,nan]==[1,2,nan]
  True ***
  &gt;&gt;&gt; nan == nan
  False
  &gt;&gt;&gt; [nan] == [nan]
  True ***
  &gt;&gt;&gt; [nan, nan] == [nan for i in range(2)]
  True ***
  &gt;&gt;&gt; [nan, nan] == [float(nan) for i in range(2)]
  True ***
  &gt;&gt;&gt; float(nan) is (float(nan) + 1)
  False
  &gt;&gt;&gt; float(nan) is float(nan)
  True ***
  </code></pre>