Skip to content

Instantly share code, notes, and snippets.

@giwa
Last active August 29, 2015 14:17
Show Gist options
  • Save giwa/10eb25940a0b10ea95fa to your computer and use it in GitHub Desktop.
Save giwa/10eb25940a0b10ea95fa to your computer and use it in GitHub Desktop.
Pythonicに sum of square を返す表現の歴史を振り返る ref: http://qiita.com/giwa/items/ed40135be78cede1af26
result = []
for i in range(n):
s = i * i
result.append(s)
print sum(result)
print sum([i * i for i in range(n)])
def squares(n):
for i in xrange(n):
s = i * i
yield s
print sum(squares(n))
print sum(i * i for i in xrange(n))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment