Last active
January 3, 2016 03:29
-
-
Save phalt/8402736 to your computer and use it in GitHub Desktop.
Cool python things
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
# List comprehensions | |
# Generate a list of integers from 1 to 10 in one line | |
l = [i for i in range(1, 11)] | |
# Lambdas | |
# Anonymous functions assigned to variables | |
f = lambda x: x % 2 == 0 | |
for i in l: | |
f(i) | |
# prints true if number divisble by 2 | |
# But we could also do this in one list comprehension: | |
l = [i for i in range(1, 11) if i % 2 == 0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment