Packaging work into functions, and the four ways Python stores collections of things: lists, dictionaries, tuples and sets.
Why this stage exists
This is the direct on-ramp to everything that follows. A Python list is a . A Python dictionary is a . Those are two of the most important structures in the whole roadmap, and you meet them here as ordinary everyday tools before anyone asks you to build one yourself in week 17. Using something fluently first, then learning how it works underneath, is exactly the right order.
What you are learning — 6 topics
Functions
A named block of steps you can run whenever you want. You give it some information to work with, and it hands something back.
Think of it likeA vending machine. You put something in, a fixed process happens, something comes out. You do not need to know what happens inside to use it.
You define one with def, a name, and brackets listing what it needs: def add(a, b): followed by an indented block. The names in brackets are called parameters — they refer to whatever gets passed in when the function runs.
The word return sends a value back to whoever called the function, and immediately stops the function. Anything written after a return never runs.
Here is the confusion that trips up nearly everyone, and it is worth reading twice. print shows a value to a human looking at the screen. return hands a value back to the rest of your program. A function that prints instead of returning looks like it works, because you see the right answer appear — but the value has gone nowhere, and total = add(2, 3) leaves total holding nothing at all. If you feel stupid when you hit this, you should not: everybody hits it.
Functions are how you stop repeating yourself, but more importantly they are how you make a problem smaller. A problem you cannot solve in one go often becomes obvious once you split it into three functions that each do one thing.
Where you meet it in real softwareEvery piece of software you have used is functions calling functions. It is the basic unit of organisation in programming.
A variable created inside a function only exists inside that function. When the function finishes, it is gone.
This is a feature, not a limitation. It means two different functions can both use the name count without interfering with each other. Each function gets its own private space.
A function can read variables defined outside it, but if it assigns to a name, that name becomes local to the function. This asymmetry surprises people once and then makes sense.
The practical rule while you are learning: pass what a function needs in through its parameters, and hand results back with return. Reaching outside a function for values produces code that is very hard to reason about later.
Where you meet it in real softwareScope is why large programs written by many people do not collapse into name collisions.
An ordered collection. Things stay in the order you put them, you can reach any one instantly by its position number, and you can add and remove freely.
You write one as names = ["ana", "bo", "cy"]. You reach into it with square brackets and a position: names[0] is "ana". Counting starts at zero, so the last of three items sits at position 2. names[-1] is a shortcut for the last one.
Slicing takes a range: names[0:2] gives you the first two. The end number is not included, which matches how range() behaves — Python is consistent about this once you notice the pattern.
append adds to the end. Lists can hold anything, including other lists, which is how you make a grid: a list of rows, where each row is itself a list.
Underneath, a Python list is a dynamic : a block of memory with the items laid out one after another. That layout is why reaching any position is instant, and it is also why inserting at the front is slow — everything after it has to shuffle along. You will build one of these from scratch in week 15, and this is the fact that will make sense of it.
What it costsReaching a position by number is O(1). Searching for a value whose position you do not know is O(n). Adding to the end is O(1) on average. Inserting at the front is O(n).
Where you meet it in real softwareSearch results, rows from a spreadsheet, the pixels of an image — anything you loop over more often than you rearrange.
A lookup table. Instead of numbered positions you store things under labels of your own choosing, and fetch them back by that label.
Think of it likeA contacts app. You do not scroll to position 47, you look up the name.
You write one as ages = {"ana": 30, "bo": 25}. The labels are called keys and the things stored are called values. You fetch with ages["ana"].
The remarkable property is that looking something up takes the same time whether the dictionary holds ten items or ten million. It does not search. It calculates where the item must be from the key itself and goes straight there. That calculation is called hashing, and building it yourself is one of the main events of week 17.
Keys must be things that cannot change — text and numbers are fine, lists are not. This is one of the reasons tuples exist.
In practice, dictionaries are probably the structure you will reach for most often in your working life. Counting how many times each word appears, grouping records by category, remembering answers you have already worked out — all dictionaries.
What it costsLooking up, adding and removing are all O(1) on average — the size of the dictionary does not matter.
Where you meet it in real softwareCaches, configuration, counting occurrences, grouping records, and the internals of nearly every database and compiler.
A tuple is a list that cannot be changed after it is made. A set is a collection that silently refuses duplicates and keeps no order.
Tuples are written with round brackets: point = (3, 4). Because they cannot change, they can be used as dictionary keys where lists cannot. They are also a clear signal to whoever reads your code that this group of values belongs together and is not meant to be edited.
Sets are written with curly brackets: seen = {1, 2, 3}. Adding something already there does nothing. Checking whether something is in a set is instant, in the same way as a dictionary lookup — a set is essentially a dictionary with keys and no values.
The practical use of a set is removing duplicates and testing membership. Removing duplicates from a list of a million items with a loop takes ages; doing it with a set is one line and near-instant. That gap between the obvious approach and the right structure is, in miniature, what this entire roadmap is about.
What it costsChecking whether something is in a set is O(1). Checking whether it is in a list is O(n). For large collections that difference is enormous.
Where you meet it in real softwareRemoving duplicates, checking permissions, tracking which pages a web crawler has already visited.
A compact one-line way to build a new list out of an existing one.
Instead of creating an empty list and appending in a loop, you write doubled = [x * 2 for x in numbers]. Read it left to right as: make a list, of x times two, for each x in numbers.
You can filter at the same time: evens = [x for x in numbers if x % 2 == 0].
This is genuinely idiomatic Python rather than showing off, and you will see it constantly in other people's code, so it is worth being comfortable reading. But do not force it — if a comprehension gets long enough that you have to squint at it, an ordinary loop is the better choice.
Where you meet it in real softwareTransforming and filtering collections, which is most of data handling.
Reading about this stage is not the same as finishing it. Type every one of these from a blank file rather than copying — the writing is the part that teaches.
Word-frequency counter
Take a paragraph of text and print how many times each word appears. Use a dictionary with the word as the key and the count as the value. This is the single most useful small program for understanding what dictionaries are for.
Contact book
Add a contact, search for one, delete one, list them all. Store them in a dictionary and give each operation its own function. Your first program with a real structure rather than one long script.
Grade tracker
Store several scores per student and compute each student's average. A dictionary where each value is a list — your first nested structure.
Write find_max yourself
Write a function that takes a list of numbers and returns the largest, without using Python's built-in max(). Keep a running best-so-far and compare each item against it. It looks trivial, and it is the pattern underneath a surprising number of later algorithms.
Remove duplicates, twice
Remove duplicates from a list two ways: once with a loop that checks whether each item is already in a new list, and once by converting to a set. Then run both on a list of 100,000 items and time them. The difference you feel here is exactly what Big-O notation describes.
You are done with this stage when
Exit checkYou can write a function that takes a list and returns a dictionary, and explain out loud what every line of it does.
If you cannot do this, repeat the stage rather than moving on. Nothing later gets easier by skipping it.
Worth knowing before you start
This is one of the two places beginners most often quit. The return-versus-print confusion makes people feel stupid, and it is not a sign of anything — everyone hits it. If a function seems to work but the value vanishes, check whether you printed when you meant to return.
This stage corresponds to Phase 0 — Functions & Built-in Data Structures in the source roadmap.