Creating simple python loop

python

#1

Dear colleagues,

I need help with python where I’ve tried to achieve the results as shown op the picture. But apparently I’m way to dumb to understand how :sob: (feeling seriously bad about myself)… can anybody please help me?

The point is that I have n-th amount of sublist with different values which needed to be increasingly add-up.

test.dyn (9.4 KB)


#2

Hello @alex.berg!

Here is a suggestion for you:

OUT = []
last_item = 0
OUT.append(last_item)
for sub_list in IN[0]:
	for item in sub_list:
		OUT.append(item+last_item)
	last_item = last_item+sub_list[-1]

#3

@Einar_Raknes Thank you very much!

Although now I feel even dumber because the solutions seems so simple… but anyhow many thanks!