Test if all values of a list is True or False using Python

grasshopper
python
unhandled

(David Couto) #1

Hi everyone.

I’m trying to create a python script that reads a list of values ​​and tests if they satisfy the condition, like the image below.

However, I’d like it to return only one True if all values ​​satisfy the condition or only one false if any of the values ​​do not satisfy the condition, instead of a list of all values tested one by one.

Thanks in advance.


(Michael Pryor) #2

(Lando Schumpich) #3

You have to declare ‘list access’ in your input x (right click) or else the ghpython will run once for every item in your input list and append all solutions to a.

Code would be like this:

a = True
for item in x:
    if item > someLowerBound and item < someUpperBound:
        continue
    else:
        a = False
        break

I wrote this on my phone so it’s not tested