Explore Library
Quiz

Generator vs List Comprehension

Understand the key practical difference between generator expressions and list comprehensions.

You need to sum the squares of 10 million numbers: sum(x*x for x in range(10_000_000)). Why is the generator expression preferable to sum([x*x for x in range(10_000_000)]) here?