Help: how to create sublists based on summation values in a different list

Can’t get this to work.
I would like to make consequential sublists of the main list based on the closest summation of the numbers compared to another list of intended sums. I hope this makes sense,

I have a main list with 200 numbers.
Then another list of sums (60 and 100).

I intend to take items adding them up one by one from the main list till the sum is just above 60, then create a new list of those numbers.
Then with the remaining list, take more items till the sum is just above 100, and create a new list of those.
Finally, return a list with two sublists of the numbers that add up to the coresponding sums.

kindly help

_test for loop.dyn (5.5 KB)

What is your expected output?

list[0][0] all the items from the begining of the list that the sum is just above 60
list[0][1] the rest of the items in the list whose sum is just above 100

I don’t quite understand, but I would probably do something like this:

1 Like

Thanks! The first Python Script highlighted in blue provides the desired results.

Do you know why my Designscript code block fails?

There are at least one paranthesis placed wrongly, think that the list assignment might also be off… Generally I prefer using python and or nodes to accomplish my tasks

1 Like

I think I should also consider switching to Python Scripts, they seem more forgiving.

Thanks alot.

Hey @Jonathan.Olesen, I just noticed something. The script is producing a summation of a sequence starting from 0, regardless of the contents of the main list.

I need the final list to contain the items in the main list, I hope it’s clear now.

Exchange the append of ‘‘j’’ with IN[0][j]

1 Like

Awesome! Thanks

@Sylar46 Possible with nodes too
conSum.dyn (34.7 KB)

2 Likes

Thanks @Vikram_Subbaiah

1 Like

Very true there was a parenthesis placed wrongly in the while statement, among 2 other errors. Thanks :innocent: