title: Python: group a list into sublists by a equality of projected value
body: <p>Is there a nice pythonic way of grouping a list into a list of lists where each of the inner lists contain only those elements that have the same projection, defined by the user as a function?</p>
  
  <p>Example:</p>
  
  <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; x = [0, 1, 2, 3, 4, 5, 6, 7]
  &gt;&gt;&gt; groupby(x, projection=lambda e: e % 3)
  [[0, 3, 6], [1, 4, 7], [2, 5]]
  </code></pre>
  
  <p>I don't care about the projection itself, just that if it is equal for some elements these must end up in the same sublist.</p>
  
  <p>I'm basically looking for a python equivalent of the haskell function <a href="http://hackage.haskell.org/package/base-4.9.0.0/docs/GHC-Exts.html#v:groupWith" rel="noreferrer"><code>GHC.Exts.groupWith</code></a>:</p>
  
  <pre class="lang-hs prettyprint-override"><code>Prelude&gt; import GHC.Exts
  Prelude GHC.Exts&gt; groupWith (`mod` 3) [0..7]
  [[0,3,6],[1,4,7],[2,5]]
  </code></pre>