title: Split list into sub-lists based on attribute value
body: <p>I have an array of objects that have a <code>suit</code> attribute, and I want to split into sub arrays based on which suit the object has.  I currently am using this:</p>
  
  <pre><code>    for c in cards:
          if c.suit.value == 0:
              spades.append(c)
          elif c.suit.value == 1:
              diamonds.append(c)
          elif c.suit.value == 2:
              clubs.append(c)
          else:
              hearts.append(c)
  </code></pre>
  
  <p>I have tried to use <code>itertools.groupby</code> as follows:</p>
  
  <pre><code>suits = [list(g) for g in intertools.groupby(cards, lambda x: x.suit.value)]
  </code></pre>
  
  <p>But this just yields:</p>
  
  <pre><code>[[3, &lt;itertools._grouper object at 0x000000000296B2E8&gt;], ...]
  </code></pre>
  
  <p>My first approach works, I just imagine there is a simple pythonic one liner that accomplishes what I need.</p>