functools.reduce(func, iter, [initial_value]) cumulatively performs an operation on all the iterable’s elements and, therefore, can’t be applied to infinite iterables. func must be a function that takes two elements and returns a single value.$_{functools.reduce()}$ takes the first two elements A and B returned by the iterator and calculates$_{func(A, B)}$ . It then requests the third element, C, calculates$_{func(func(A, B), C)}$ , combines this result with the fourth element returned, and continues until the iterable is exhausted. If the iterable returns no values at all, a TypeError exception is raised. If the initial value is supplied, it’s used as a starting point and func(initial_value, A) is the first calculation. >>> import operator , functools >>> functools .reduce(operator.concat, [ 'A','BB','C']) 'ABBC' >>> functools .reduce(operator.concat, []) Traceback (most recent call last): ... TypeError: reduce() of empty sequence with no initial value >>> functools .reduce(operator.mul, [ 1,2,3],1) 6 >>> functools .reduce(operator.mul, [], 1) 1 >>> import functools , operator >>> functools .reduce(operator.add, [1,2,3,4],0) 10 >>> sum([1,2,3,4]) 10 >>> sum([]) 0 import functools # Instead of: product=functools .reduce(operator.mul, [ 1,2,3],1) # You can write: product=1 for i in [1,2,3]: product*=i itertools.accumulate([ 1,2,3,4,5])=> 1,3,6,10 ,15 itertools.accumulate([ 1,2,3,4,5], operator.mul)=> 1,2,6,24 ,120 A related function is itertools.accumulate(iterable, func=operator.add) . It performs the same calculation, but instead of returning only the final result,$_{accumulate()}$ returns an iterator that also yields each partial result: For many uses of$_{functools.reduce()}$ , though, it can be clearer to just write the obvious$_{for}$ loop: If you use operator.add() with functools.reduce() , you’ll add up all the elements of the iterable. This case is so common that there’s a special built-in called$_{sum()}$ to compute it: 16