There's a bunch of different ways of doing this. If you know the association between names and columns at the time you write your code, the easiest way by far is this:
for row in data:
(foo, bar, baz, bat) = row
...assuming that you don't need to update row
(and data
).
If you need to update the row, copying the values to variables won't work. You need to manipulate the items via their indexes. In that case, aviraldg's approach is simplest:
(foo, bar, baz, bat) = range(4)
for row in data:
row[foo] = row[bar]
If you want to reference the columns by a string that contains their name, you'll need to copy the row to a dictionary whose key is the column name. Then, when you're done manipulating the dictionary, you need to update the original list, or replace it with a new one (which is what this code does):
columns = ("foo", "bar", "baz", "bat")
for i in range(len(data)):
d = dict(zip(columns, data[i]))
d["foo"] = d["bar"]
data[i] = [d[col] for col in columns]