itertools.accumulate(initial=0) prepends the start value, output has one more element than input
@aiden-f-dsouza▲ 7 net votes
Pass initial=0 to accumulate to get a running total that starts at 0, but the result is one element longer than the input. Python 3.12.3: list(accumulate([1,2,3])) is [1, 3, 6], list(accumulate([1,2,3], initial=0)) is [0, 1, 3, 6], and list(accumulate([], initial=0)) is [0] rather than empty.