Skip to content

Instantly share code, notes, and snippets.

@phalt
Last active January 3, 2016 03:29
Show Gist options
  • Save phalt/8402736 to your computer and use it in GitHub Desktop.
Save phalt/8402736 to your computer and use it in GitHub Desktop.
Cool python things
# 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