CoursePython from Scratch to Intermediate · Module 7: Modules, the Standard Library and Packages · part 48 of 75
Part 48 · Module 7: Modules, the Standard Library and Packages

Lesson 3: Paths and collections: files, tallies and groups

15 min read·14 Oct 2026
Module 7 · Lesson 3 · About 45 minutes · Needs: Module 5 (lists, tuples, dictionaries, list comprehensions), Module 6 (functions), Module 7 Lessons 1 and 2 (import, date, timedelta)

The situation

Amira has two questions this morning. First: "Where do the shelf's files live, and is the loans file really there?" Second: "Who borrows the most, and what does each member have out right now?"

Python ships tools for both in its standard library, the modules that come with every Python: pathlib for files and folders, and collections for tallies, groups and small records. You will follow one member throughout: Kwame (M04), who borrows the most and has three books out today.

AMIRA'S TWO QUESTIONS where are the files? is loans.csv there? who borrows most? what is out, with whom? pathlib Path, mkdir, exists, glob collections Counter, defaultdict both ship with Python: the standard library
Amira's two questions map to two standard-library modules (blue, your code): pathlib for files and folders, collections for tallies and groups.

The rest of this part opens with an account

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