reduce and opeator

Reduce is operation that reducing an array into a single value.

For example multiplying all element in the array

a=[1,2,3,4,5,6]

from functools import reduce
from operator import mul
a=[1,2,3]

reduce(mul, a) 
# 6

# or with lambda

reduce(lambda x, y: x*y, a)
# 6

Last updated