title: Finding an index in a list using 2 lists
body: <p>Im trying to find the index of each 1 that is at the end of each group(sequence) of 1s. The output for the example below should be <code>[17, 12, 9, 5, 1]</code>.</p>
  
  <p>I can find the 1 at index 17 using the formula below but I also need to find the 1 at index 12. (i.e. it's the last instance of 1 in each sequence (or group) of 1s)</p>
  
  <pre><code>list = [1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0]
  
  index_list1 = [i for i, v in enumerate(list) if v == 1] 
  index_list0 = [i for i, v in enumerate(list) if v == 0]
  
  val1 = None
  for i in index_list1[::-1]:
     if i &lt; index_list0[-1]:
        val1 = i
        break
     else:
        val1 = index_list1[-1]
  if val1 is not None:
     index1 = val1
  </code></pre>