code: def groupby(objects, key, reducegroup=list):
      
      kgroups = itertools.groupby(sorted(objects, key=key), key)
      return {k: reducegroup(group) for k, group in kgroups}
docs: :param objects: a sequence of objects with a key value
      :param key: the key function to extract the key value
      :param reducegroup: the function to apply to each group
      :returns: a dict {key value: map(reducegroup, group)}
  
      >>> groupby(['A1', 'A2', 'B1', 'B2', 'B3'], lambda x: x[0],
      ...         lambda group: ''.join(x[1] for x in group))
      {'A': '12', 'B': '123'}