History of sum of square
1990: Basic Python
result = []
for i in range(n):
s = i * i
result.append(s)
print sum(result)
2000: List Comprehensions PEP202
print sum([i * i for i in range(n)])
2001: Generators PEP255
def squares(n):
for i in xrange(n):
s = i * i
yield s
print sum(squares(n))
2004: Generator Expressions PEP289
print sum(i * i for i in xrange(n))
Recommended Posts