Is there a Pythonic way to refer to columns of 2D lists by name?
I import a lot of tables from the web so I made a general purpose function that creates 2 dimensional lists out of various HTML tables. So far so good. But the next step is often to parse the table row by row.
# Sample table. # In real life I would do something like: table = HTML_table('url', 'table id') table = [ ['Column A', 'Column B', 'Column C'], ['One', 'Two', 3], ['Four', 'Five', 6] ] # Current code: iA = table.index('Column A') iB = tabel.index('Column B') for row in table[1:]: process_row(row[iA], row[iC]) # Desired code: for row in table[1:]: process_row(row['Column A'], row['Column C'])