title: Grouping elements in a list of lists
body: <p>I have a few records which reads as follows:</p>
  
  <pre><code>list1= [['corner grant and main reef road, new state area, springs', 'springs'],
       ['corner grant and main reef road, new state area, springs', 'palm springs'],
       ['corner grant and main reef road, new state area, springs', 'edenvale']]
  </code></pre>
  
  <p>I want my record to look like this:</p>
  
  <pre><code>list2= ['corner grant and main reef road, new state area, springs', 'springs | palm springs | edenvale']
  </code></pre>
  
  <p>I wrote the following code to accomplish this:</p>
  
  <pre><code>for i in range(len(list1)-1):
      if list1[i][0] == list1[i+1][0]:
          list2.append([list1[i][0], list1[i][1] + "|" + list1[i + 1][1]])
      else:
          pass
  </code></pre>
  
  <p>This works if I have two elements in a list and are consecutive entries, it however fails if there are more than 2 items and are not consecutive.
  Could anyone please point out a suitable way to accomplish this. </p>