title: return index of last non-zero element in list
body: <p>I get data in the following format:</p>
  
  <pre><code>[-2, -2, 0, 0, 0, 0, 0]
  [-2, 20, -1, 0, 3, 0, 0]
  </code></pre>
  
  <p>with each line being a different input. The lists could be longer than 7 elements.  I need to return the index position of the last non-zero element, so:</p>
  
  <pre><code>[-2, -2, 0, 0, 0, 0, 0]
  &gt;&gt;&gt; 1
  [-2, 20, -1, 0, 3, 0, 0]
  &gt;&gt;&gt; 4
  </code></pre>
  
  <p>The following code does this most of the time:</p>
  
  <pre><code>def getIndex(list):
      for element in reversed(list):
          if element != 0:
              return list.index(element)
  </code></pre>
  
  <p>However, it doesn't work when there are two of the same numbers, as in the first example above, which returns <code>0</code> because <code>-2</code> is in both the 0th and 1st position of the list.</p>
  
  <p>So how to get the index of the last non-zero element of a list, even when there are elements with the same value?</p>