def group_by_field(table, name):
 try:
  col_index = table[0].index(name)
 except ValueError as e:
  raise ValueError(("Couldn't find name %s in headers: %s" % (name, table[0])))
 result = defaultdict(list)
 for row in table[1:]:
  (header, state) = (row[0], row[col_index])
  result[state].append(header)
 return result

def group_by_field ( table , name ) : try : col_index = table [ 0 ] . index ( name ) except ValueError as e : raise ValueError ( ( "Couldn't find name %s in headers: %s" % ( name , table [ 0 ] ) ) ) result = defaultdict ( list ) for row in table [ 1 : ] : ( header , state ) = ( row [ 0 ] , row [ col_index ] ) result [ state ] . append ( header ) return result
returns dict of field_state:[row_headers] from table .