Iterators, Generators and Decorators
How for really works, generators that produce values one at a time, itertools and functools, decorators, and context managers you write yourself.
Python code is full of loops, but few learners know what a loop does underneath. This phase opens the box: the iteration protocol that every for loop uses, then generators, which let a function hand back values one at a time instead of building a whole list first.
Next come the standard-library toolboxes built on those ideas (itertools and functools), and then decorators: the @ lines that wrap a function with extra behaviour such as logging, caching or retrying. You will write simple ones, ones that take arguments, ones written as classes, and your own context managers with contextlib.
These are the tools behind real AI code. A generator that yields tokens is how a streamed model answer is read. batched splits documents into groups for an embedding API. A retry decorator survives a flaky network call. lru_cache avoids paying twice for the same lookup. The phase ends with functional style, so you can choose well between a comprehension, map and a loop.
Practise this phase
Hands-on exercises: write the code, run it, and press Check to have it tested automatically.