Nested if statement returns nothing in list of lists
<p>Here is my list (of lists):</p>

<pre><code>mylist = [ [1, "John", None, "Doe"], [2, "Jane", "group1", "Zee"], [3, "Lex", "group2", "Fee"]]

y = 2

for sublist in mylist:
    if sublist[0] == y:   # meaning the third list
        if sublist[2] == None:
            print(sublist[2]) # this should print nothing
        else:
            print(sublist[2]) #this should print something
</code></pre>

<p>The end result is that nothing prints for this code. </p>

<p>I am trying to do a check for situations where I have a <code>None</code> value in my list (of lists). This method above doesn't seem to work.</p>

<p>I cannot figure out why it refuses to print anything at all, but I assume the nested <code>if sublist[2] == None:</code> may have something to do with it.</p>

<blockquote>
  <p>I am trying to do a check for situations where I have a None value in my list (of lists)</p>
</blockquote>

<p>Then just check for membership with <code>in</code> for every sub list:</p>

<pre><code>for sublist in mylist:
    if None in sublist:
        # do your check
        print("None in list: ", sublist)
</code></pre>

<p>prints:</p>

<pre><code>None in list:  [1, 'John', None, 'Doe']
</code></pre>

<p>If you want to just see if a <code>None</code> exists in general just use <code>any</code>:</p>

<pre><code>any(None in sub for sub in mylist)
</code></pre>

<p>which returns <code>True</code> since <code>None</code> is in <code>mylist[0]</code></p>

python python-3.x python-3.4