Skip to content

Instantly share code, notes, and snippets.

@narma
Created July 19, 2010 14:37
Show Gist options
  • Save narma/481485 to your computer and use it in GitHub Desktop.
Save narma/481485 to your computer and use it in GitHub Desktop.
Real groupby of python itertools
def realgroupby(it, key):
from itertools import groupby, chain
d = {}
for k, ii in groupby(it, key):
if k in d:
d[k] = chain(d[k], list(ii))
else:
d[k] = list(ii)
return d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment