itertools.accumulate() versus functools.reduce()
It seems that accumulate keeps the previous results, whereas reduce (which is known as fold in other languages) does not necessarily. e.g. list(accumulate([1,2,3], operator.add)) would return [1,3,6] whereas a plain fold would return 6 Also (just for fun, don’t do this) you can define accumulate in terms of reduce def accumulate(xs, f): return reduce(lambda a, … Read more