Python Quest

Track 6 · Lesson 10 of 12

Sorting records with key functions

Sort records by any field with key=lambda, reverse the order, break ties with tuple keys, and mix ascending and descending.

About 40 minIntermediate4 exercises

You will be able to

  • Sort with sorted(..., key=...) using a lambda that picks the sort value
  • Use reverse=True and explain how sorting is stable
  • Sort by several fields at once with a tuple key
  • Mix ascending and descending order by negating numeric keys

Included with a Formula Quest membership

It has 4 graded exercises with feedback, hints and solutions. Python Quest is included in Formula Quest memberships that cover Python; membership and billing are managed on Formula Quest.

View Formula Quest memberships

Tracks 1 and 2, the first lesson of every track, the playground and the dataset library are free.