Functional programming finished

This commit is contained in:
2025-03-10 16:45:40 +00:00
parent 27ec86a094
commit 0ce49095d6
3 changed files with 144 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
from functools import reduce
my_list = [1,2,3]
def accumalator(acc, item):
print(acc, item)
return acc + item
print(reduce(accumalator, my_list, 10))
# What reduce does?
# reduce take the function given and take item from the
# iterable and pass to function given to it. The first
# parameter is the value initialized as the 3rd argument
# to the reduce function. It do the processing and returns
# a value which is used as next initialiizing value for the
# first argument of the function provided in the reduce function
# and so on for all items in iterable.