rows = sorted(rows, key=group_key)
return itertools.chain.from_iterable(op(group_rows) for k, group_rows in
    itertools.groupby(rows, key=group_key))
Is there an implementation of Hadley's ddply for python?