A generator costs the same whatever you put in it
pythonThe first kata most people meet. Both expressions describe a million squares; only one of them holds a million squares.
import sys squares_list = [n * n for n in range(1_000_000)] squares_gen = (n * n for n in range(1_000_000)) sys.getsizeof(squares_list) # ~8 MB - every square exists at once sys.getsizeof(squares_gen) # ~200 B - each square exists for one loop # The kata: keep the pipeline lazy end to end, then measure again. total = sum(n * n for n in range(1_000_000) if n % 3 == 0)