The functools module is for higher-order functions. Apply function of two arguments cumulatively to the items of iterable, from left to right, so as to reduce the iterable to a single value.

If the optionalinitializer is present, it is placed before the items of the iterable in the calculation, and serves as a default when the iterable is empty.

Example Iterable contains only one item, reduce() will return that item.Example If iterable is empty and the initializer is given, reduce() will return the initializer.

Example 3:Function argument is given as max(), to find a running maximumExample 4: If the initial value is mentioned, it will start accumulating from the initial value.Example 5: If the iterable is empty and the initial parameter is mentioned, it will return the initial value.Example 6: If iterable contains one element and the initial parameter is not mentioned, it will return that element.Example Iterating through the iterator using for loop

Related Articles