title: iterating through list of tuples while accessing the previous and next elements
body: <p>I'm trying to iterate of a list of tuples while still having access to the previous tuple and the next tuple.Specifically I need to compare the y coordinate of the previous current and next tuple.
  <br>
  <br>This is my list of tuples that I'm using as input: 
  <code>[(1,1),(2,2),(3,4),(4,3),(5,5),(6,3.5),(7,7),(8,8),(9,9),(10,8),(11,9.5),(11,7.5),(12,12),(13,1.5)]</code></p>
  
  <p>I initially used this code segment to be able to have access to the previous, current and next elements:</p>
  
  <pre><code>def previous_and_next(some_iterable):
  
      prevs, current, nexts = tee(some_iterable, 3)
      prevs = chain([None], prevs)
      nexts = chain(islice(nexts, 1, None), [None])
  
      return zip(prevs, current, nexts)
  </code></pre>
  
  <p>But I can't access the elements of the tuple using this function as it returns an error about subscripting. Im open to new ideas or different functions, as this bit is clearly not what I need.</p>
  
  <p>For more clarification this is the function that I am currently trying to implement</p>
  
  <pre><code>UF = UnionFind()
  sortedlist = sorted(pointcloud, key=lambda x: x[1])
  
  for previous, current, nxt in previous_and_next(sortedlist):
  
         if previous[1] &gt; current[1] and nxt[1] &gt; current[1]:
             UF.insert_objects(current)
         elif previous[1] &lt; current[1] and nxt[1] &lt; current[1]:
             c=UF.find(previous[1])
             d=UF.find(nxt[1])
             UF.union(c,d)
         else:
              c=UF.find(previous[1])
              UF.union(current,previous)
  
  
  
  return 
  </code></pre>