title: How to group list of tuples?
body: <p><em>Note</em>: I know how I can do this of course in an explicit for loop but I am looking for a solution that is a bit more readable.</p>
  
  <p>If possible, I'd like to solve this by using some of the built-in functionalities. Best case scenario is something like</p>
  
  <pre><code>result = [ *groupby logic* ]
  </code></pre>
  
  <hr>
  
  <p>Assuming the following list:</p>
  
  <pre><code>import numpy as np
  np.random.seed(42)
  
  N = 10
  
  my_tuples = list(zip(np.random.choice(list('ABC'), size=N),
                       np.random.choice(range(100), size=N)))
  </code></pre>
  
  <p>where <code>my_tuples</code> is </p>
  
  <pre><code>[('C', 74),
   ('A', 74),
   ('C', 87),
   ('C', 99),
   ('A', 23),
   ('A', 2),
   ('C', 21),
   ('B', 52),
   ('C', 1),
   ('C', 87)]
  </code></pre>
  
  <p>How can I group the indices (integer value at index 1 of each tuple) by the labels A, B and C using <code>groupby</code> from itertools?</p>
  
  <p>If I do something like this:</p>
  
  <pre><code>from itertools import groupby
  
  #..
  
  [(k,*v) for k, v in dict(groupby(my_tuples, lambda x: x[0])).items()]
  </code></pre>
  
  <p>I see that this delivers the wrong result.</p>
  
  <p>The desired outcome should be </p>
  
  <pre><code>{
    'A': [74, 23, 2],
    # ..
  }
  </code></pre>