using reduce when you need to single cumulative result output
example we wanted multiply entire list items or addition them each item.
[1,2,3] if addition then 1+2+3 become 6
for that we need to import the reduce first from functools module
it accept function and iterables
e.g. reduce(function, iterlabes)
use when you wanted to flat the result or output and do not use for simple operations or single operation.
code :
from functools import reduce
def add(s1, s2):
return s1 + s2
asequence = [1, 2, 3]
print(reduce(add, asequence))
Put Your Thought or Query Here