title: How to use itertools.groupby when the key value is in the elements of the iterable?
body: <p>To illustrate, I start with a list of 2-tuples:</p>
  
  <pre><code>import itertools
  import operator
  
  raw = [(1, "one"),
         (2, "two"),
         (1, "one"),
         (3, "three"),
         (2, "two")]
  
  for key, grp in itertools.groupby(raw, key=lambda item: item[0]):
      print key, list(grp).pop()[1]
  </code></pre>
  
  <p>yields:</p>
  
  <pre><code>1 one
  2 two
  1 one
  3 three
  2 two
  </code></pre>
  
  <p>In an attempt to investigate why:</p>
  
  <pre><code>for key, grp in itertools.groupby(raw, key=lambda item: item[0]):
      print key, list(grp)
  
  # ---- OUTPUT ----
  1 [(1, 'one')]
  2 [(2, 'two')]
  1 [(1, 'one')]
  3 [(3, 'three')]
  2 [(2, 'two')]
  </code></pre>
  
  <p>Even this will give me the same output:</p>
  
  <pre><code>for key, grp in itertools.groupby(raw, key=operator.itemgetter(0)):
      print key, list(grp)
  </code></pre>
  
  <p>I want to get something like:</p>
  
  <pre><code>1 one, one
  2 two, two
  3 three
  </code></pre>
  
  <p>I am thinking this is because the key is within the tuple inside the list, when in fact the tuple gets moved around as one. Is there a way to get to my desired output? Maybe <code>groupby()</code> isn't suited for this task?</p>