In Python, generators are helper objects for managing long sequences of data. When list or tuple is created, it loads all its items into memory at once. A generator, by contrast, only loads and returns 1 item at a time.
In this example, we'll access a list of common Dutch surnames via a generator!
Side note: The for x in y
construct actually makes a generator of the iterable y
.