Introduction to Programming using Python 1st Edition

Published by Pearson
ISBN 10: 0132747189
ISBN 13: 978-0-13274-718-9

Chapter 11 - Multidimensional Lists - Programming Exercises - Page 390: 11.26

Answer

code

Work Step by Step

# 11.26 (Row sorting) Implement the following function to sort the rows in a twodimensional # list. A new list is returned and the original list is intact. # def sortRows(m): # Write a test program that prompts the user to enter a 3*3 matrix of numbers and # displays a new row-sorted matrix. def main(): SIZE = 3 print("Enter a 3 by 3 matrix row by row: ") m = [] for i in range(SIZE): line = input().split() m.append([eval(x) for x in line]) print("The row-sorted list is ") printMatrix(sortRows(m)) def printMatrix(m): for i in range(len(m)): for j in range(len(m[i])): print(m[i][j], end=" ") print() def sortRows(m): result = [] for row in m: result.append(row) for row in result: row.sort() return result main()
Update this answer!

You can help us out by revising, improving and updating this answer.

Update this answer

After you claim an answer you’ll have 24 hours to send in a draft. An editor will review the submission and either publish your submission or provide feedback.