GHPython: Creating two list based on "if"

Hi every one, I have a list of numbers in a Grasshopper panel, and I want to use the GhPython component to achieve the following: If the sum of the numbers is less than 20, I want to place them in one list; if the sum is greater than or equal to 20, I want to place them in another list. but it doesn’t work. Do you have any idea?

if sum(d) >= v:
    a = d
else:
    b = d

Azam.gh (10.4 KB)

1 Like

1 Like

Thank you, Mahdiyar, for your assistance. However, my question is not quite the same. Please refer to the attachment. I’ve attempted both methods, but unfortunately, neither has proven effective.


Calculate the lenght for cutting HSS (1).gh (31.7 KB)

Thanks Joseph, I’ve tried to use it but it doesn’t work in my data.
Calculate the lenght for cutting HSS (1).gh (31.7 KB)

In the attachment, you have 7 numbers. Do you want to know when their total goes over 20 like this?


Azam.gh (12.2 KB)

1 Like

:+1:
Thank you.

Another question; if we have to repeat the the components for a longer list; it could be replaced by loop? How should I write this?


Azam (1).gh (10.3 KB)

What you really mean is “How would you write this?”

1 Like