Answer to Question #201131 in Python for sajid pasha

Question #201131

Given a M x N matrix, write a program to print the matrix after ordering all the elements of the matrix in increasing order

sample input:

3 3

1 20 3

30 10 2

5 11 15

output:

1 2 3

5 10 11

15 20 30


please give the accurate answer for this question


1
Expert's answer
2021-05-31T05:39:54-0400
n, m = map(int, input('n, m : ').split())
l = list()
for i in range(n):
    l.append(list(map(int, input().split())))
a = list()
for item in l:
    for i in item:
        a.append(i)

a.sort()

k = 0
for i in range(n):
    for j in range(m):
        l[i][j] = a[k]
        k += 1

for i in l:
    for j in i:
        print(j, end=' ')
    print()

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