CoursePython from Scratch to Intermediate · Module 10: Intermediate Python · part 67 of 75
Part 67 · Module 10: Intermediate Python

Lesson 1: One loan at a time with iterators and generators

15 min read·14 Oct 2026
Module 10 · Lesson 1 · About 50 minutes · Needs: Module 8 (reading files, CSV, try and except), Module 7 (the booknook package and datetime), Module 5 (lists and comprehensions)

The situation

Amira's request for this module is "Make sure it never breaks." Her first worry is size. "Forty loans is nothing. Will the program cope with years of loans?"

So far every function built a whole list, then handed it over. This lesson teaches a second way: hand over one loan at a time, only when asked. You will follow the rows of data/loans.csv one at a time until the four overdue loans come out: Jonah's L04, Ben's L13, Kwame's L21 and Lena's L23.

TWO WAYS TO HAND OVER 40 LOANS build the whole list all 40 rows in memory then return them hand over one at a time one row in memory only when asked L01 L02 ... L40 L01 next row later
So far every function built the whole list first (grey, the old way); this lesson hands over one loan at a time (blue, the normal path from now on).

The rest of this part opens with an account

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