concept reduce function in category data

appears as: reduce function, The reduce function, A reduce function
Mastering Large Datasets with Python: Parallelize and Distribute Your Python Code

This is an excerpt from Manning's book Mastering Large Datasets with Python: Parallelize and Distribute Your Python Code.

  • The reduce function performs one-to-any transformations and is a great way to assemble data into a final result.
  • Figure 5.2. A reduce function has three parts: an accumulator, which specifies reduce’s behavior, a sequence, which we reduce over, and an initial value, which we use to start our reduce operation.

    Listing 5.1 provides an example of how summation with reduce may look. Two things are worth noting about this short bit of code. First, we need to import reduce from the functools library. The reduce function is not a default import like map, though it is available with any distribution of Python. In deprecated versions of Python (2.7 and below), reduce was available by default.