Transpose of a matrix



Problem to transpose the given matrix.



   
        1   2   3
If n =  4   5   6
        7   8   9

                  1   4   7
Transpose of n =  2   5   8
                  3   6   9




Example-1:


Input    : n = [[1,2,3],[4,5,6],[7,8,9]]
Output   : [[1, 4, 7], [2, 5, 8], [3, 6, 9]]


Example-2:


Input    : n = [[1,2],[5,6]]
Output   : [[1, 5], [2, 6]]   


Example-2:


Input    : n = [[1,2,3],[4,5,6]]
Output   : [[1, 4], [2, 5], [3, 6]]







Solution




n = [[1,2,3],[4,5,6],[7,8,9]]

k = []

for i in range(len(n[0])):

    l = []

    for j in range(len(n)):

        l.append(n[j][i])

    k.append(l)
    
print(k)



Output



[[1, 4, 7], [2, 5, 8], [3, 6, 9]]