Brainlag
  1. Python
  2. Advanced
28/42 lessons

Sorting with a key

25 min5 exercisesPremium

Sort anything in Python: sorted() with key= and reverse=, lambda functions, sorting by several things at once, dicts by value, and max() and min() with a key.

The skill
Sort anything by any rule with key functions, ties included.
You make
A price list, an artist chart and a league table with tie-breaks.

Premium lesson

£7.99 a month or £59 a year. Cancel any time.

Builds on 27 Comprehensions. Free to try: Python Foundations and the playground.

Step 1 of 8
exercise_1.py

You've reached the good stuff.

5 exercises in this lesson, checked as you type. Premium opens every lesson after Foundations, in all four courses.

Python 3.13