Skip to content

Instantly share code, notes, and snippets.

@ekohl
Created January 21, 2010 20:02
Show Gist options
  • Save ekohl/283141 to your computer and use it in GitHub Desktop.
Save ekohl/283141 to your computer and use it in GitHub Desktop.
Simple demonstration of higher order functions in python
#!/usr/bin/python
from operator import add
lijst = range(50)
print "lijst:", lijst
f = lambda x: x * 2
print "map:", map(f, lijst)
g = lambda x: x % 2 == 0
print "filter:", filter(g, lijst)
print "reduce:", reduce(add, lijst)
print "list comprehension:", [ f(x) for x in lijst if g(x) ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment