Lessons 1–5 · About 60 min per lesson
Filtering, transforming and sorting
Make records from different sources consistent and comparable.
Lesson breakdown
- Lesson 1
Filter and transform records with comprehensions.
- Lesson 2
Represent fields in dictionaries and handle missing values.
- Lesson 3
Trim whitespace and normalise letter case.
- Lesson 4
Use a set to detect duplicates and define which record survives.
- 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 → [].