title: Python - manipulate list only if its length is greater than X
body: <p>For a small test I am doing, I need to print the 5th element of a list, if there is one. </p>
  
  <pre><code>with open (my_file, 'r') as my_probe:
      for fileLine in my_probe:
          src_string = fileLine.split()
          my_list = list(src_string) # The list may contain any number of items
          if len(my_list) &gt; 3: # Only if lists is longer than 4 items
              print("Info I need: "+my_list[4])
  </code></pre>
  
  <p>When I run the code, however, it nevertheless tries to print the 5th element of lists with less then 5 elements and thus returns an error showing I am trying to print unexisting item:</p>
  
  <pre><code>Traceback (most recent call last):
    File "my_script.py", line 70, in &lt;module&gt;
      print ("Info I need: "+my_list[4])
  IndexError: list index out of range
  </code></pre>
  
  <p>Could anyone suggests a way to overcome this problem?</p>
  
  <p>Thanks in advance!</p>