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 398: 11.51

Answer

code

Work Step by Step

# 11.51 (Sort students) Write a program that prompts the user to enter the students’ # names and their scores on one line, and prints student names in increasing order # of their scores. (Hint: Create a list. Each element in the list is a sublist with two # elements: score and name. Apply the sort method to sort the list. This will sort # the list on scores.) lst = input("Enter students’ names and scores: ").split() studs = [] for i in range(0, len(lst), 2): studs.append([lst[i], int(lst[i + 1])]) studs.sort(key=lambda x: x[1]) for x in studs: print(format(x[0], '8s'), end='') print(x[1])
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.