-1

Fascinated by zip, it occured to me that one could use it for matrix-transpose.
Here is the python code:

import sys
n = raw_input("enter the number of rows of the matrix:")
x = []
for i in range(int(n)):
    y = map(int,raw_input().split())
    x.append(y)
mat = zip(*x)

print ""

for i in mat:
    for j in i:
        sys.stdout.write(str(j))
        sys.stdout.write(" ")
    sys.stdout.write("\n")

But i am not quite satisfied with how my code looks.. How do i improve it?

Thanks!

Edit:

Input:
1 2
3 4
5 6
7 8

Output:
1 3 5 7 
2 4 6 8 
256ABC
  • 143
  • 4

1 Answers1

2

matrix transpose with zip:

a = [[1,2],[3,4]]

a_t =list(map(list, zip(*a)))
Alireza Afzal Aghaei
  • 1,184
  • 10
  • 27