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")]
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")]
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")]
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: