Advertisement
elena1234

reduce function in Python

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