Trying to figure out to to transpose a list of lists ( i believe this a matrix not sure.) I know there may be more advanced and concise ways of doing this but trying to limit myself to using what my course has covered so far.
grid = [['apples', 'oranges', 'cherries', 'banana'],
['Alice', 'Bob', 'Carol', 'David'],
['dogs', 'cats', 'moose', 'goose']]
i know how to do this by printing. I'd do it like this.
for j in range(len(grid[0])):
for i in range(len(grid)):
print(grid[i][j],end=' ')
print('')
but I'm struggling to figure out how to do this by actually saving it to a variable. this saves it in the right order but I don't know what to add to separate it into different lists
newgrid = []
for j in range(len(grid[0])):
for i in range(len(grid)):
newgrid.append([grid[i][j])
# list separation here
end result should be
grid = [['apples', 'Alice', 'dog'],
['oranges', 'Bob', 'cats'],
['cherries', 'Carol', 'moose'],
['banana', 'David', 'goose']]