Answer to Question #231250 in Python for bhuvana

Question #231250

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


1
Expert's answer
2021-08-31T00:52:51-0400
M=int(input(""))
N=int(input(""))
nums= []
for i in range(0,M):
    val_string=input("")
    vals=val_string.split()
    for val in vals:
        nums.append(int(val))


nums.sort()
nums2d=[]
nums2d = [nums[r*N:(r+1)*N] for r in range(0,M)]
print()
for row in nums2d:
    for e in row:
        print(e, 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