Up to now, we’ve worked with collections that fit in memory all at once — a list of names, a dictionary of scores. But ML datasets are often too big for that. Iterators and generators let us produce values one at a time, on demand, without ever holding the whole collection in memory.
What’s in this section
- Iterables vs iterators — the difference, and why it matters
iter()andnext()— the protocol every loop uses under the hood- Generator expressions — list comprehensions that yield values lazily
- The
yieldkeyword — write your own generators
This section is short but high-leverage. Data pipelines, file streams, and dataset loaders all rely on what you’ll learn here.