I am looking to flip the rows and columns on a 2D list and am running into trouble. Python won't allow a value to be assigned to an uninitialized 'cell'. I am not sure how to initialize my grid since I don't know the length ahead of time. The following:
data = list()
maReader = csv.reader(open('TEST.csv', 'rb'), delimiter=',', quotechar='"')
for rindex, row in enumerate(maReader):
for iindex, item in enumerate(row):
data[iindex][rindex] = item
fails with a "IndexError: list assignment index out of range" error. I could loop through twice, the first time to count columns and rows, than initialize the grid, than loop again and assign values, but that seems awfully wasteful.
I am pretty new to Python and figure there is a simple way to do this that I am missing.
Thanks for the help.