Skip to content

Commit

Permalink
add groupby customizations
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Aug 20, 2013
1 parent 3c1b116 commit a0ff1f4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions toolshed/__init__.py
Expand Up @@ -12,10 +12,17 @@

def groupby(iterable, key=0, filter=None):
"""
wrapper to itertools.groupby that
1) returns a list of each group, rather than a generator
2) accepts integers or strings as the key and automatically
converts them to callables with itemgetter(key)
wrapper to itertools.groupby that returns a list of each group, rather
than a generator and accepts integers or strings as the key and
automatically converts them to callables with itemgetter(key)
Arguments:
iterable: iterable
key: string, int or callable that tells how to group
Returns:
an iterable where each item is the key and a *list* of that
group. (itertools.groupby returns a generator of that group).
e.g. groupby(iterable, 0)
"""
Expand Down

0 comments on commit a0ff1f4

Please sign in to comment.