def groupby(fn, coll):
d = collections.defaultdict(list)<EOL>for item in coll:<EOL><INDENT>key = fn(item)<EOL>d[key].append(item)<EOL><DEDENT>return dict(d)<EOL>
Group elements in sub-collections by fn

    :param fn: a function
    :param coll: a collection
    :returns: a dictionary

    >>> groupby(len, ['John', 'Terry', 'Eric', 'Graham', 'Mickael'])
    {4: ['John', 'Eric'], 5: ['Terry'], 6: ['Graham'], 7: ['Mickael']}