CoursePython from Scratch to Intermediate · Module 5: Collections · part 36 of 75
Part 36 · Module 5: Collections

Lesson 4: Nested data and comprehensions, the whole catalogue

17 min read·14 Oct 2026
Module 5 · Lesson 4 · About 50 minutes · Needs: Module 5 Lessons 1 to 3 (lists, tuples and sets, dictionaries), Module 4 (for loops, if)

The situation

Amira wants the whole shelf in the computer, so she can ask it things. "Which books are gothic? How many of each genre? Which have two copies?"

One book fits in one dictionary; the shelf is 24 of them. This lesson puts collections inside collections, reaches into them step by step, and shows a short way to build a new list from an old one. We follow one book throughout: B06, Frankenstein, the copy Jonah has out.

24 book records one per book CATALOGUE list of 24 dicts by_genre 7 groups a new list e.g. gothic titles one shape in, new shapes out
The 24 books become one list of dictionaries (blue, your data), which can then be regrouped by genre or boiled down to a new list (green, the results you want).

The rest of this part opens with an account

Signing up is free and takes one email. Nothing to pay, and nothing renews.