title: How to avoid 'IndexError: list index out of range' error?
body: <p>Suppose there are a list called '<code>my_list</code>' and an int variable called '<code>list_index</code>'. Basically, the list '<code>my_list</code>' might change over time and hence the '<code>list_index</code>' might raise '<code>IndexError: list index out of range</code>'. However, I just want to make record when this error occurs since it is not that important. To avoid this error, my basic solutions currently are:</p>
  <pre><code># My first way
  if my_list[list_index: list_index +1]: 
      print('item exists')
  else:
      print('item does not exist')
  
  # My second way
  if -len(my_list) &lt;= list_index &lt; len(my_list):
      print('item exists')
  else:
      print('item does not exist')
  </code></pre>
  <p>Except for <code>try/except</code> statement, are there other solutions to avoid the 'IndexError: list index out of range' error?</p>