Skip to content

Instantly share code, notes, and snippets.

@mrocklin
Created June 6, 2013 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrocklin/5722155 to your computer and use it in GitHub Desktop.
Save mrocklin/5722155 to your computer and use it in GitHub Desktop.
def test_groupby():
names = ['Alice', 'Bob', 'Charlie', 'Dan', 'Edith', 'Frank']
assert groupby(len, names) == {3: ['Bob', 'Dan'],
5: ['Alice', 'Edith', 'Frank'],
7: ['Charlie']}
even = lambda x: x % 2 == 0
assert groupby(even, range(10)) == {False: [1, 3, 5, 7, 9],
True: [0, 2, 4, 6, 8]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment