Mod Python for Sublists

Below is a python script to create a running total of the numbers from the list it receives. I need this to work on sub-lists (currently it only works on a flat list). Can anyone provide direction on how to accomplish this? Thanks.

list = IN[0]
mass = 0
masspart = []
if hasattr(list, "__iter__"):
    for i in range(0,len(list)):
    mass = mass + list[i]
    masspart.append(mass)
else:
    masspart.append(list)
OUT = masspart

There is a node in lunchbox package that already does this pretty well. I would use that instead.

This is the one from Lunchbox. It does not work on sub-lists.

@Konrad_K_Sobon I think @smcdonald is using the same node from Lunchbox.

@smcdonald You could try setting Lacing to Longest it would work or else use this code.


2 Likes

it works pretty well:

1 Like

Thanks, It is actually the “Partials” output i am looking for, but the lacing works for that as well in the Lunchbox node.
I usually try to avoid putting in nodes from packages to make it easier for the people that will be using the scripts (I can barely get them to run the correct version of dynamo, telling them to install packages is just extra effort), so I will use the logic from the code you posted to try to get the partials to work in just the python node.
Thanks for the help.