Advertisement
elena1234

functions in Python with lambda ( map , filter , reduce )

Feb 8th, 2022
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.25 KB | None | 0 0
  1. from functools import reduce
  2.  
  3.  
  4. my_list = [1, 2, 3, 4, 5]
  5.  
  6. print(list(map(lambda x: x * 2, my_list))) # [2, 4, 6, 8, 10]
  7.  
  8. print(list(filter(lambda x: x % 2 == 0, my_list))) # [2, 4]
  9.  
  10. print(reduce(lambda acc, element: acc + element, my_list, 0)) # 15
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement