Generator Memory Versus List Memory
Both functions return the same value for the same n:
def sum_of_squares_list(n: int) -> int:
squares = [x * x for x in range(n)]
return sum(squares)
def sum_of_squares_gen(n: int) -> int:
squares = (x * x for x in range(n))
return sum(squares)
For n = 10_000_000, how do their memory footprints compare, and why?
Sign in to answer questions and track your progress
Sign In