def group_by_min_key(input_list):
 key = itemgetter(0)
 value = itemgetter(1)
 res_dict_1 = {}
 for (key, group) in groupby(input_list, key):
  res_dict_1[key] = [value(x) for x in group]
 key = itemgetter(1)
 value = itemgetter(0)
 res_dict_2 = {}
 for (key, group) in groupby(input_list, key):
  res_dict_2[key] = [value(x) for x in group]
 if (len(res_dict_1) > len(res_dict_2)):
  return (res_dict_2, 1)
 else:
  return (res_dict_1, 0)

def group_by_min_key ( input_list ) : key = itemgetter ( 0 ) value = itemgetter ( 1 ) res_dict_1 = { } for ( key , group ) in groupby ( input_list , key ) : res_dict_1 [ key ] = [ value ( x ) for x in group ] key = itemgetter ( 1 ) value = itemgetter ( 0 ) res_dict_2 = { } for ( key , group ) in groupby ( input_list , key ) : res_dict_2 [ key ] = [ value ( x ) for x in group ] if ( len ( res_dict_1 ) > len ( res_dict_2 ) ) : return ( res_dict_2 , 1 ) else : return ( res_dict_1 , 0 )
this function takes a list with tuples of length two inside: [ .