Intermediate Python
The language's own idioms, classic data structures and algorithms, testing and packaging.
-
Lesson 15 min read
Python Big O notation: measure speed with timeit
What Big O means in Python, how to measure growth with timeit at three sizes, the five curves you meet most, and what list, dict and set operations cost.
-
Lesson 24 min read
Python iterators and generators: yield, next and itertools
What a for loop really does with iter and next, how yield turns a function into a generator, why a generator expression uses almost no memory, and the lazy tools in itertools.
-
Lesson 34 min read
Python closures and scope: LEGB, nonlocal and late binding
Where Python looks for a name, how a function inside a function remembers its variables, how nonlocal changes them, and why lambdas made in a loop all return the same value.
-
Lesson 45 min read
Python decorators explained: @wraps, arguments and lru_cache
What the at sign above a function really does, how to write a decorator, how functools.wraps keeps the name, how to give a decorator arguments, and how lru_cache makes recursive Fibonacci instant.
-
Lesson 54 min read
Python classes explained: dunder methods, property and super
How a Python class prints itself with dunder methods, hides a function behind an attribute with @property, builds objects with @classmethod, and extends a parent class with super().
-
Lesson 64 min read
Python type hints explained: str, list[int] and int | None
How to add type hints to a Python function, describe a list with list[int], mark a value that might be None with int | None, and what a type checker does with the hints.
-
Lesson 74 min read
Python stacks and queues: list, deque and why pop(0) is slow
What a stack and a queue are, how to build a stack from a list and a queue from a deque, and why pop(0) on a list costs O(n) while popleft on a deque does not.
-
Lesson 84 min read
Python linked lists from scratch: Node class and head
How a linked list works in Python: a Node class that holds a value and a link, the head, the None that ends the chain, how to walk it, and why adding at the front is O(1) but finding an item is not.
-
Lesson 94 min read
Python recursion explained: call stack and base case
How recursion works in Python: a function that calls itself on a smaller problem, the call stack that holds the waiting calls, the base case that stops them, and the RecursionError you get without one.
-
Lesson 104 min read
Python binary search explained: low, high and mid
How binary search works in Python: check the middle of a sorted list, drop half, move low and high past the middle, and why a million items take about 20 steps.
-
Lesson 114 min read
Python sorting algorithms: bubble sort, merge sort, sorted()
How sorting works in Python: bubble sort swaps neighbours in O(n squared), merge sort splits and merges in O(n log n), and sorted() with key does the job for you in real code.
-
Lesson 125 min read
Python hash tables: how a dict finds a key so fast
How a Python dict works inside: the key becomes a hash, the hash picks a slot, so lookup is O(1). Collisions, why a list cannot be a key, and how a set fits in.
-
Lesson 134 min read
Python heapq: heaps and priority queues explained
How a Python heap always gives you the smallest item first. The heap rule, pop and push at O(log n), heapq on a plain list, and a tiny task scheduler with its real output.
-
Lesson 145 min read
Python trees and traversal: binary trees and in-order walk
How a Python binary tree is built from nodes, what makes it a search tree, and how an in-order walk visits every node in sorted order. A small recursive function with its real output.
-
Lesson 155 min read
Python HTTP and JSON APIs: fetch data with urllib
How to call a web API in Python with only the standard library: send a request with urllib, turn the JSON response into a dictionary, and handle a bad address, a down network or a 404. One short script with its real output.
-
Lesson 164 min read
Python testing with pytest: write and run tests
How to test Python code with pytest: how it finds tests by name, how a test is a plain assert, what a failure shows, and how to run one test on many inputs with parametrize. One short test file with its real output.
-
Lesson 174 min read
Python packaging with uv: build and publish a package
How to package Python code with uv: start a package with uv init, name a command in pyproject.toml, build a wheel with uv build, and publish it to PyPI. One small function with its real output.