I’m currently working on a project in Dynamo where I need to calculate the cumulative sum of a list of numbers. I have set up a Code Block to perform the calculation using an imperative block, but it’s returning an empty list despite my attempts to troubleshoot. Is there any other way to achive results of first code block in more practical way ?
lst;
runningVal = 0;
sums = [];
[Imperative]
{
for (i in lst)
{
runningVal = runningVal+i;
sums = List.AddItemToEnd(runningVal, sums);
}
return = sums;
};
I think that covers all the bases.
If you need to do this on lists of lists adjust the lacing as required (@L2<1L> in design script, for list in lists in imperative and Python, and list levels when using nodes).