Skip to content

Instantly share code, notes, and snippets.

@elsapet
Last active August 29, 2015 14:27
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 elsapet/fd3dbd9f04c66ce751b6 to your computer and use it in GitHub Desktop.
Save elsapet/fd3dbd9f04c66ce751b6 to your computer and use it in GitHub Desktop.
# collect the even numbers in a given range
# 1. using regular py
evens = []
for i in range(1, 10):
if i % 2 == 0:
evens.append(i)
# 2. using list comprehension
[i for i in range(1, 10) if i % 2 == 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment