Created
September 16, 2019 19:28
-
-
Save JeffLabonte/8acc410b6057fa8c71340aa94bcb559c to your computer and use it in GitHub Desktop.
Saved from https://stackoverflow.com/questions/13638898/how-to-use-filter-map-and-reduce-in-python-3
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
>>> def f(x): | |
return x % 2 != 0 and x % 3 != 0 | |
>>> filter(f, range(2, 25)) | |
[5, 7, 11, 13, 17, 19, 23] | |
>>> def cube(x): | |
return x*x*x | |
>>> map(cube, range(1, 11)) | |
[1, 8, 27, 64, 125, 216, 343, 512, 729, 1000] | |
>>> def add(x,y): | |
return x+y | |
>>> reduce(add, range(1, 11)) | |
55 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment