Created
January 4, 2019 15:32
-
-
Save m-x-k/98d932540466539568648d1990714140 to your computer and use it in GitHub Desktop.
Python Map Filter Reduce examples
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
from functools import reduce | |
check = [1, 2, 3, 4, 5] | |
if __name__ == '__main__': | |
print(list(map(lambda x: x * 3, check))) # OUTPUT: [3, 6, 9, 12, 15] | |
print(list(filter(lambda x: x < 3, check))) # OUTPUT: [1, 2] | |
print(reduce(lambda x, y: x * y, check)) # OUTPUT: 120 (i.e. 1 * 2 * 3 * 4 * 5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment