Hi everyone.
I have problem about list.
I have a list
[0] = 0
[1] = 1219 + 0
[2] = 2438 + 1219
[3] = 3657 + 2438
How to do it to
[0] = 0
[1] = 1219
[2] = 3657
[3] = 6095.
please help me. Thanks.
Thank you so much.
You can see picture below. How to do?
Though here is a out of the box node option.
List.RestOfItems - Removes first item in list
List.FirstItem - Gets first item in list
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.
Thanks everyone, but I want to return a list as below:
init:
[0]=0
[1]=500
[2]=1200
[3]=800
[4]=600
return result:
[0]=0
[1]=500 ([0]+[1]–>0 + 500)
[2]=1700 ([1]+[2]–>500 + 1200)
[3]=2500 ([2]+[3]–>1700 + 800)
[4]=3100 ([3]+[4]–>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([0]);
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.
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:
Thank you so much.