I need to create a function that transpose a matrix (to basically transform rows into columns, and columns into rows) by modifying directly the reference of the list (the function should not return any value, or print anything, it should be modified directly through the reference :
The following matrix :
1 2 3
4 5 6
7 8 9
should be transformed into
1 4 7
2 5 8
3 6 9
However, my code is not accepted :
def transpose(matrix):
matrix = [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]
I can't understand why... Is this code modifying only the value of the list, and not the reference ?
Any suggestion ? (I need to use "for ... " function from python).
Thank you in advance !