title: How does Python if and isinstance work in this example?
body: <p>I am a relative Python newbie (so apologies for what is probably a stupid question) - I need to look through the elements list below and print the first element of each list if it is an integar - I must admit I can't completely understand solution#1 doesn't work and why solution#2 does:</p>
  
  <pre><code>elements = [
      [1, 4, 6, 7],
      [4, 5, 6],
      [6, 7, 8],
      [],
      ["nodata", "nodata"],
      [1, 3]
              ]
  </code></pre>
  
  <p>solution#1:</p>
  
  <pre><code>for i in elements:
      if isinstance(i[0], int):     #  check if first element of each list is an int
          print(i[0])
  </code></pre>
  
  <p>(I get an list index out of range error, but not sure why - is it because one of the lists is empty?? - this seems to be the case as this works:</p>
  
  <pre><code>for i in elements:
      if len(i) &gt; 0 and isinstance(i[0], int):
          print(i[0])
  </code></pre>
  
  <p>solution#2:</p>
  
  <pre><code>for i in elements:
      if i and isinstance(i[0], int):     # what does 'if i and ....' mean here?? does it mean 'if i is not empty' and???
          print(i[0])
  </code></pre>
  
  <p>Thanks a lot for any help in advance!</p>