code: def groupby(fn, coll):
      
      d = collections.defaultdict(list)
      for item in coll:
          key = fn(item)
          d[key].append(item)
      return dict(d)
docs: 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']}