 Plus value next in List

Hi everyone.
I have a list
 = 0
 = 1219 + 0
 = 2438 + 1219
 = 3657 + 2438
How to do it to
 = 0
 = 1219
 = 3657
 = 6095.

2 Likes

Thank you so much. You can see picture below. How to do?

Is something as follows how you would have expected it to work?

1 Like

Though here is a out of the box node option.

List.RestOfItems - Removes first item in list
List.FirstItem - Gets first item in list

1 Like

List.AddItemToFront to add a 0 before the list, then a + node. You’ll be adding 0 to index 1, index 1 to index 2, index 2 to index 3, index n-1 to index n. Make sure lacing is set to shortest on your + node.

2 Likes

Thanks everyone, but I want to return a list as below:
init:
=0
=500
=1200
=800
=600
return result:
=0
=500 (+–>0 + 500)
=1700 (+–>500 + 1200)
=2500 (+–>1700 + 800)
=3100 (+–>2500 + 600).

Did you try the List.AddItemToFront method? The X input on the plus node is your original list, the result of the add item to front node is your Y input.

what is red box?

The number 0

Ah! I didn’t understand your issue. You want mass addition, that is the sum of all items leading up to that point. So:
Math.Sum();
Math.Sum([0,1]);
Math.Sum([0,1,2]);
Math.Sum([0,1,2,3]);
Math.Sum([0…n]);

There is a node called ‘MassAddition’ in the lunchbox package which will do the trick.

You can also use a List.DropItems node to drop a range of items from -(List.Count(lst)-1) to 0 items from the list and sum those. It’s a fairly simple design script statement - I’ll write it up in the morning and post back of the lunchbox option doesn’t work for you.

2 Likes

Thanks @JacobSmall. Good job.
I used ‘MassAddition’ in the lunchbox package.

1 Like

Sorry i thought you wanted to add the current value to previous value in a list. To get the sum total as you go along a list would be done as follows:

1 Like

Thank you so much.