Skip to content

Instantly share code, notes, and snippets.

@m-x-k
Created January 4, 2019 15:32
Show Gist options
  • Save m-x-k/98d932540466539568648d1990714140 to your computer and use it in GitHub Desktop.
Save m-x-k/98d932540466539568648d1990714140 to your computer and use it in GitHub Desktop.
Python Map Filter Reduce examples
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