I need to create a function that transposes a given matrix (without using numpy or any other additional packages of Python).The matrix can be square or not. I have been able to do it if it is square but not the other case. I have seen with a debugger that the problem is list index out of range but I don't know really how to solve the problem. Thanks for your help.
Edit: I am not allowed to use zip. Is there any other way?
This is my code:
def transpose(M):
T=[]
for i in range(0,len(M)):
row=[0]*len(M[0])
T.append(row)
for i in range(len(M)):
for j in range(len(M[0])):
T[i][j]=M[j][i]
return T
print(transpose([[9, 9, 7, 6], [6, 5, 1, 4], [1, 5, 5, 8]]))