code: def group_dict(items, keyfunc):
      
      result = collections.defaultdict(list)
      for i in items:
          key = keyfunc(i)
          result[key].append(i)
      return result
docs: Return a list defaultdict with ``items`` grouped by ``keyfunc``.
  
      >>> sorted(group_dict('eggs', lambda x: x).items())
      [('e', ['e']), ('g', ['g', 'g']), ('s', ['s'])]