itertools.accumulate() versus functools.reduce()

前端 未结 3 1487
礼貌的吻别
礼貌的吻别 2021-02-02 10:40

In Python 3.3, itertools.accumulate(), which normally repeatedly applies an addition operation to the supplied iterable, can now take a function argument as a parameter; this me

3条回答
  •  [愿得一人]
    2021-02-02 10:51

    You can see in the documentation what the difference is. reduce returns a single result, the sum, product, etc., of the sequence. accumulate returns an iterator over all the intermediate results. Basically, accumulate returns an iterator over the results of each step of the reduce operation.

提交回复
热议问题