Loop thru list with addition, grab index of value that exceeds limit

Maybe I am missing something I want to use Math.Random to create a list of colors as long as another list.

OK< started this as different topic and dumped in wrong image. Although, this is useful question. I have a dynamo graph that adds the list indices to themselves but i can not access the index value of when the threshold is crossed.

I am new to python maybe I am coding this totally wrong. I want to be able to access the index of the value that trips the x value beyond 100. I want x to return to 0 and start counting again from that index until it hits 100 again.

Thank you,
-Mark

OK, so I scrapped the python script and went back to the List.Scan to add each index to the next:

then in order to find where to cut the list I chose to use the nodes below:

Hope my simple question and solution I came up with helps those looking for a similar answer.

1 Like

Also found out later that the Lunchbox 'Mass Addition" node does the addition, but still would need to know the index.

def SmIn(nm:var[]..[],lm)
{
	return=[Imperative]
	{
		ct=0;
		ad=0;
		ix=0;
		sm={};
		si={};

		while(ct<List.Count(nm))
		{
			while(ad<lm && ct<List.Count(nm))
			{
				ad=ad+nm[ct];
				sm[ix]=ad;
				si[ix]=ct;
				ct=ct+1;
			}
			ad=0;
			ix=ix+1;
		}
		return={sm,si};
	}
};
1 Like

With Python …

ad=0
ct=0
sm=[]
sm=[]
si=[]
while ct<len(IN[0]):
	while (ad<100) and (ct<len(IN[0])):
		ad = ad + IN[0][ct]
		ct=ct+1
	sm.append(ad)
	si.append(ct-1)
	ad=0
OUT=[sm,si]
1 Like

Vikram,

Thank you very much for your time and effort! I will post my results, this seems like what I was attempting to do without the proper syntax. Still learning the languages.

Thank you,
-Mark

1 Like