Lessons 1–5 · About 60 min per lesson

Filtering, transforming and sorting

Make records from different sources consistent and comparable.

Lesson breakdown

  1. Lesson 1

    Filter and transform records with comprehensions.

  2. Lesson 2

    Represent fields in dictionaries and handle missing values.

  3. Lesson 3

    Trim whitespace and normalise letter case.

  4. Lesson 4

    Use a set to detect duplicates and define which record survives.

  5. Lesson 5

    Use a multi-field sort key to settle ties.

Worked example

Sort Bo 8, Mia 10 and Ana 8 by descending score, then ascending name.

How to solve it

Use (-score, name) as the key. The result is Mia 10, Ana 8, Bo 8.

Assignment

Trim and lowercase a name list, ignore blanks, remove duplicates and return alphabetical order.

Check your result

[" Bo ", "mia", "BO", ""] → ["bo", "mia"]; an empty list → [].