Created
January 21, 2010 20:02
-
-
Save ekohl/283141 to your computer and use it in GitHub Desktop.
Simple demonstration of higher order functions in python
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
#!/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