A list holds all its values at once. A generator holds almost nothing, and produces each value only at the moment it is wanted. This is called lazy evaluation, and it changes what a program can do: it can process a file bigger than memory, work with a sequence that never ends, and stop early without wasted effort. This lesson shows those three benefits, and how to chain generators into pipelines.
More lessons in Complete Python Programming