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

Lab: Answer what is out and who has it

14 min read·14 Oct 2026
Module 5 · Lab · About 50 minutes · Needs: lessons 1 to 4 of this module, and Module 4 (for loops, if, shelf days)

What you are building

THREE COLLECTIONS IN, FOUR ANSWERS OUT CATALOGUE 24 books MEMBERS 6 members LOAN_ROWS 40 tuples lookups by id, checked 9 loans out 4 late 18 on shelf of 27 copies who has what Kwame at limit per genre books, copies, out
The lab turns three pasted collections (blue) into lookups and then into four checked answers for Amira (green).

Amira's question for this module is "What is out, and who has it?" Each lesson answered a piece of it with a small slice of the data. This lab answers all of it for the whole shelf, in one notebook session, using only what this module taught: lists, tuples, sets, dictionaries, nested data and comprehensions.

You start from three collections: the catalogue of 24 books, the 6 members and the 40 loans. You turn the loans into dictionaries, build lookups from them, and then answer four questions: which loans are out, how many copies are left on the shelf, who has what, and how the shelf divides by genre. The lab ends with a report Amira can read at the counter, checked against the course's known answers.

Open a new Colab notebook, call it module-05-lab.ipynb, and run each cell in order.

The rest of this part opens with an account

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