-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransposeInPython.py
49 lines (39 loc) · 960 Bytes
/
TransposeInPython.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
'''
Question:
Given a 2D array A, your task is to convert all rows to columns and columns to rows.
Input:
First line contains 2 space separated integers, N - total rows, M - total columns.
Each of the next N lines will contain M space separated integers.
Output:
Print M lines each containing N space separated integers.
SAMPLE INPUT -
3 5
13 4 8 14 1
9 6 3 7 21
5 12 17 9 3
SAMPLE OUTPUT
13 9 5
4 6 12
8 3 17
14 7 9
1 21 3
'''
#Solution
#Create List
elements = []
value = input()
lst = value.split(" ")
row = int(lst[0])
column = int(lst[1])
for i in range(row):
#Appending list inside elements to create it multidimensional
elements.append([])
column_values = input()
col_lst = column_values.split(" ")
for col in range(column):
elements[i].append(col_lst[col])
# Printing Element in Transpose Order
for col in range(column):
for i in range(row):
print(elements[i][col], end=" ")
print(end="\n")