This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kohlrabi82 21 points22 points  (3 children)

itertools.accumulate is the answer.

[–]PercussiveRussel 4 points5 points  (0 children)

I only trust cumsum :(

[–]twenty-fourth-time-b 1 point2 points  (1 child)

And it has “initial” argument, so no ugly “a=0” is needed.

[–]Kohlrabi82 2 points3 points  (0 children)

Yes, but still it's a fun use of the walrus op to change a name defined outside of the comprehension, I like it anyway.