2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Pythonicに sum of square を返す表現の歴史を振り返る

2
Last updated at Posted at 2015-03-20

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))
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?