title: Remove both adjacent tuples from lists
body: <p>Given this list:</p>
  
  <pre><code>[(1, 's'), (2, 'e'), (2, 's'), (3, 'e')]
  </code></pre>
  
  <p>This is a representation of potentially overlapping intervals, e.g. <code>1 --&gt; 2</code> and <code>2 --&gt; 3</code>, I've brought it into this representation for easier processing (see <a href="https://stackoverflow.com/a/48112301/119861">this answer</a> for context)</p>
  
  <p>I'd like to remove the pair <code>(2, 'e')</code> -- <code>(2, 's')</code> because the end (<code>e</code>) of the one interval is at the same number (<code>2</code>) as start (<code>s</code>) of the next interval. So the result should be</p>
  
  <pre><code>[(1, 's'), (3, 'e')]
  </code></pre>
  
  <p>And would represent <code>1 --&gt; 3</code>.</p>
  
  <p><strong>Edit</strong>: It's also possible that the intervals are overlapping, e.g. <code>1--&gt;4</code> and <code>2--&gt;3</code>. That would be represented in this list of tuples (Note that the list is already sorted): <code>[(1, 's'), (2, 's'), (3, 'e'), (4, 'e')]</code>. In this case nothing needs to be done as no two tuples share the same number.</p>
  
  <p>I've come up with this reduce:</p>
  
  <pre><code>import functools
  functools.reduce(lambda l,i: l[:-1] if i[0] == l[-1][0] and i[1] != l[-1][1] else l + [i], a[1:], [a[0]])
  </code></pre>
  
  <p>Are there nicer ways to achieve that?</p>