Last active
August 29, 2015 14:17
-
-
Save giwa/10eb25940a0b10ea95fa to your computer and use it in GitHub Desktop.
Pythonicに sum of square を返す表現の歴史を振り返る ref: http://qiita.com/giwa/items/ed40135be78cede1af26
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result = [] | |
for i in range(n): | |
s = i * i | |
result.append(s) | |
print sum(result) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print sum([i * i for i in range(n)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def squares(n): | |
for i in xrange(n): | |
s = i * i | |
yield s | |
print sum(squares(n)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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