Best April deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Searching
Sorting – sort()
8. Sorting orders for various variable types – exercise
Sorting – sorted()
Sorting – reverse() and reversed()
Summary

Instruction

Great work! Let's do one more exercise related to sort orders.

Exercise

Write a function named get_negative_sorted(input_list, max) that accepts a list of tuples (as shown in the template code). Each tuple contains two elements: a person's name and the number of points they received.

Your task is to return a new list of tuples. Each tuple should have two elements: the difference between that person's score and the max score (expressed as a negative number) and the person's name. Sort the list in descending order by the number of negative points. Return a sorted list. Consider this input:

max = 100
input_list = [
  ('Priscilla Cross', 34),
  ('Yvonne Tate', 78),
  ('Harry May', 54)
]

The output should be:

[
  (-22, 'Yvonne Tate'), 
  (-46, 'Harry May'), 
  (-66, 'Priscilla Cross')
]

Stuck? Here's a hint!

Create a new empty list. Iterate over the input list, and append new tuples to the new list based on the elements in the input list. Remember to change the order of the elements in the new tuples!