Generator Expressions ( PEP 289 ) allow us to define a “list” while not forcing the entire computation and storage in memory. A good example of the benefits of this comes from:

sum([x for x in range(10**8)]) # O(n) memory usage
sum(x for x in range(10**8)) # O(1) memory usage

They are easy to create for any custom function:

>>> g = (x**2 for x in [-3,1,7])
>>> g
<generator object <genexpr> at 0x7f24e2bd0eb0>
>>> next(g)
>>> next(g)
>>> next(g)
>>> next(g)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

All python generators are also python iterators