Say I have:
a = [[1, 1, 1, 6], [0, 2, -1, 3], [4, 0, 10, 42]]
and I want to transpose it to:
a = [[1,0,4], [1,2,0], [1,-1,10], [6,3,42]]
using loops in python. The current code that I have is:
def transpose(a):
s = []
for row in range(len(a)):
for col in range(len(a)):
s = s + [a[col][row]]
return s
But this gives me the output of:
[1, 0, 4, 1, 2, 0, 1, -1, 10]
Instead of this:
[[1,0,4], [1,2,0], [1,-1,10], [6,3,42]]
Can anyone help me? I'm still new at this stuff and don't understand why it doesn't work. Thanks so much!