Sort students

Created on Dec. 25, 2016 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"), (6, "Joshua"), (37, "Jeanette")]

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"), (37, "Jeanette"), (6, "Joshua")]

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"), (6, "Joshua"), (85, "Susan")]

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.
(Ctrl-Enter)