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

  1. Iterables vs iterators — the difference, and why it matters
  2. iter() and next() — the protocol every loop uses under the hood
  3. Generator expressions — list comprehensions that yield values lazily
  4. The yield keyword — 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.

Toggle theme (T)