Last active
April 18, 2018 13:07
-
-
Save graipher/cbdf5bbcaa7e30f48392e04f85fec9e6 to your computer and use it in GitHub Desktop.
Generator expression
This file contains hidden or 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
sum(num % i == 0 for i in range(1, int(sqrt(num)) + 1)) | |
# Equivalent to: | |
sum_ = 0 | |
for i in range(1, int(sqrt(num)) + 1): | |
if num % i == 0: | |
sum_ += 1 | |
# Inner expression: | |
l = [num % i == 0 for i in range(1, int(sqrt(num)) + 1)] | |
# Equivalent to: | |
l = [] | |
for i in range(1, int(sqrt(num)) + 1): | |
l.append(num % i == 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment