code: def select_by_key(items, sort_fn=sorted):
      
      itr = anyconfig.utils.concat(((k, v) for k in ks) for ks, v in items)
      return list((k, sort_fn(t[1] for t in g))
                  for k, g
                  in anyconfig.utils.groupby(itr, operator.itemgetter(0)))
docs: :param items: A list of tuples of keys and values, [([key], val)]
      :return: A list of tuples of key and values, [(key, [val])]
  
      >>> select_by_key([(["a", "aaa"], 1), (["b", "bb"], 2), (["a"], 3)])
      [('a', [1, 3]), ('aaa', [1]), ('b', [2]), ('bb', [2])]