def group(iterable, key):
for _, grouped in groupby(sorted(iterable, key=key), key=key):<EOL><INDENT>yield list(grouped)<EOL><DEDENT>
groupby which sorts the input, discards the key and returns the output
as a sequence of lists.