Answer to Question #205794 in Python for Chavali Anand Babu

Question #205794

sir above code correct #176332 i.e out put should be show

[13, 9, 5, 1, 2, 3, 4, 8, 12, 16, 15, 14]

[[13, 9, 5, 1], [14, 6, 7, 2], [15, 10, 11, 3], [16, 12, 8, 4]]


but original output should be show this manner


Sample Input 1
4 4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
3

Sample Output 1
13 9 5 1
14 7 11 2
15 6 10 3
16 12 8 4

Sample Input 2
3 4
1 2 3 4
10 11 12 5
9 8 7 6
2
Sample Output 2
9 10 1 2
8 11 12 3
7 6 5 4


how to archive this



1
Expert's answer
2021-06-11T05:06:50-0400
M, N = input().split(' ')
M, N = int(M), int(N)
matrix = []
for i in range(M):
	row = [int(j) for j in input().split(' ')]
	matrix.append(row)
values = [j for row in matrix for j in row]
values.sort()
output = matrix
for i in range(M):
	for j in range(N):
		output[i][j] = values[i * M + j]
print(output)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS