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.27

Answer

code

Work Step by Step

# 11.27 (Column sorting) Implement the following function to sort the columns in a twodimensional # list. A new list is returned and the original list is intact. # def sortColumns(m): # Write a test program that prompts the user to enter a 3 * 3matrix of numbers and # displays a new column-sorted matrix. def sortColumns(m): m1 = [[x[i] for x in m] for i in range(len(m))] for col in m1: col.sort() m1 = [[x[i] for x in m1] for i in range(len(m1))] return m1 print('Enter a 3-by-3 matrix row by row: ') m = [] for i in range(3): m.append(input().split()) print('The column-sorted list is ') res = sortColumns(m) for r in res: for v in r: print(v, end=' ') print()
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.