Looking back on the history of expressions that return sum of square to Pythonic

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

Looking back on the history of expressions that return sum of square to Pythonic
Looking back on the transition of the Qiita Advent calendar
Looking back on 2016 in the Crystal language
Looking back on the machine learning competition that I worked on for the first time
Looking back on the data M-1 Grand Prix 2020
[Python] Evaluate the facial expressions that appear on the face
Try to estimate the number of likes on Twitter
[Completed] bot that posts the start notification of Nico Nico Live Broadcasting to Discord on discord.py
[Concept] bot that posts the start notification of Nico Nico Live Broadcasting to Discord on discord.py
Looking back on ABC155
Follow the mystery of orthographic-pedant that suddenly appeared on GitHub !!