title: An algorithm to find transitions in Python
body: <p>I want to implement an algorithm that gets the index of letter changes. 
  I have the below list, here I want to find the beginning of every letter changes and put a result list except the first one. Because, for the first one, we should get the last index of occurrence of it. Let me give you an example:      </p>
  
  <pre><code>letters=['A','A','A','A','A','A','A','A','A','A','A','A','B','C','C','X','D','X','B','B','A','A','A','A']
  </code></pre>
  
  <p>Transitions: </p>
  
  <pre><code> 'A','A','A','A','A','A','A','A','A','A','A','A'--&gt;'B'--&gt;'C','C'--&gt;'X'--&gt;'D'--&gt;'X'--&gt;'B','B'--&gt;'A','A','A','A'
  </code></pre>
  
  <p>Here, after A letters finish, B starts, we should put the index of last A and the index of first B and so on, but we should not include X letter into the result list.<br>
  Desired result:</p>
  
  <pre><code>  [(11, 'A'), (12, 'B'), (13, 'C'), (16, 'D'), (18, 'B'), (20, 'A')]
  </code></pre>
  
  <p>So far, I have done this code, this finds other items except the (11, 'A'). How can I modify my code to get the desired result? </p>
  
  <pre><code>for i in range(len(letters)):
      if letters[i]!='X' and letters[i]!=letters[i-1]:
          result.append((i,(letters[i])))
  </code></pre>
  
  <p>My result: </p>
  
  <pre><code>[(12, 'B'), (13, 'C'), (16, 'D'), (18, 'B'), (20, 'A')] ---&gt; missing (11, 'A').
  </code></pre>