def group_by_fields(table, names):
 col_indices = map(table[0].index, names)
 result = defaultdict(list)
 for row in table[1:]:
  header = row[0]
  states = tuple([row[i] for i in col_indices])
  result[states].append(header)
 return result

def group_by_fields ( table , names ) : col_indices = map ( table [ 0 ] . index , names ) result = defaultdict ( list ) for row in table [ 1 : ] : header = row [ 0 ] states = tuple ( [ row [ i ] for i in col_indices ] ) result [ states ] . append ( header ) return result
returns dict of :[row_headers] from table .