title: python - set empty list index into to 0
body: <p>How do I detect an empty index and set an empty index in a list to 0 so it doesn't result in that error.  I'd like to set any index that is empty to 0.</p>
  <pre><code>#!/usr/bin/python
  
  l1 = [1,2,3]
  l2 = [4,5,6,7]
  
  for x in range(len(l2)):
      print (x,&quot; &quot;, l1[x])
  </code></pre>
  <p>error</p>
  <pre><code>Traceback (most recent call last):
  File &quot;/Users/user/desktop/test.py&quot;, line 7, in &lt;module&gt;
      print (x,&quot; &quot;, l1[x])
  IndexError: list index out of range
  </code></pre>
  <p>result</p>
  <pre><code>1, 2, 3, 0
  </code></pre>
  <p>I know I'm accessing an index not there.</p>