Transpose a Matrix

Lab Python Intermediate 20 points

Read r and c, then the matrix. Print its transpose (rows become columns).

Input

Line 1: r c. Then r rows.

Output

c rows of r numbers.

Example

Input

2 3
1 2 3
4 5 6

Output

1 4
2 5
3 6
Sample input available Sample output available
Editor
Python

Hints

zip(*grid) unpacks the rows and zips them together, giving columns.

Solution explanation

zip(*grid) is the Pythonic transpose.

Show solution
r, c = map(int, input().split())
grid = [input().split() for _ in range(r)]
for col in zip(*grid):
    print(*col)
Output
Answer
HOME LEARN COMMUNITY DASHBOARD