Skip to content

Instantly share code, notes, and snippets.

@graipher
Last active April 18, 2018 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graipher/cbdf5bbcaa7e30f48392e04f85fec9e6 to your computer and use it in GitHub Desktop.
Save graipher/cbdf5bbcaa7e30f48392e04f85fec9e6 to your computer and use it in GitHub Desktop.
Generator expression
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