Skip to content

Instantly share code, notes, and snippets.

@anfedorov
Created October 8, 2009 21:30
Show Gist options
  • Save anfedorov/205440 to your computer and use it in GitHub Desktop.
Save anfedorov/205440 to your computer and use it in GitHub Desktop.
from operator import itemgetter
from itertools import groupby
get_inning = itemgetter('inning')
get_half = itemgetter('half')
def group_by_inning(es):
return groupby(sorted(es, get_inning), get_inning)
def group_by_inning_by_half0(es):
return [ groupby(sorted(events, get_inning), get_inning) for events in group_by_inning(es) ]
# -- the following is possible
from andreystools import regroupby
def group_by_inning_by_half(es):
return regroupby(es, get_inning, half)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment