Sort students

Created by Antoine Mazières

As an introduction to sorting lists in Python you'll have to implement two functions.

In this exercise we represent students as a pair of (mark, full_name), so a tuple of two elements.

And in this exercises we represent students as lists of pairs, like:

>>> students = [(85, "Susan Maddox"), (6, "Joshua Tran"), (37, "Jeanette Wafer")]

Part 1

Write a function named sort_by_mark that take as argument a list of students and returns a copy of it sorted by mark in descending order. Such as:

>>> sort_by_mark(students)
[(85, "Susan Maddox"), (37, "Jeanette Wafer"), (6, "Joshua Tran")]

Part 2

Write a function named sort_by_name that take as argument a list of students and returns a copy of it sorted by name in ascending order, such as:

>>> sort_by_name(students)
[(37, "Jeanette Wafer"), (6, "Joshua Tran"), (85, "Susan Maddox")]

Advices

Take a look at the Sorting howto.

There's no corrections yet, hit the `Submit` button to send your code to the correction bot.

Keyboard shortcuts:

  • Ctrl-Enter: Send your code to the correction bot.
  • Escape: Get back to the instructions tab.

See solutions