[Python-ideas] Start argument for itertools.accumulate() [Was: Proposal: A Reduce-Map Comprehension and a "last" builtin]

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Apr 9 20:32:21 EDT 2018


Peter O'Connor wrote:
> The behaviour where the first element of the return is the same as the 
> first element of the input can be weird and confusing.  E.g. compare:
> 
>  >> list(itertools.accumulate([2, 3, 4], lambda accum, val: accum-val))
> [2, -1, -5]
>  >> list(itertools.accumulate([2, 3, 4], lambda accum, val: val-accum))
> [2, 1, 3]

This is another symptom of the fact that the first item in
the list is taken to be the initial value. There's no way
to interpret these results in terms of an assumed initial
value, because neither of those functions has a left
identity.

-- 
Greg


More information about the Python-ideas mailing list