ghPython custom component to filter input values into boolean lists

Can anyone smarter than I improve upon my redundant code below?
The goal is to filter my inputs which are integers ranging from 0 to 16 into branches of True/False values that can be used for the Cull Pattern component.
Bonus points if it’s possible to build the Cull Pattern into the Python component.

import rhinoscriptsyntax as rs

x=results
y=distinct

zero=[]
one=[]
two=[]
three=[]
four=[]
five=[]
six=[]
seven=[]
eight=[]
nine=[]
ten=[]
eleven=[]
twelve=[]
thirteen=[]
fourteen=[]
fifteen=[]
sixteen=[]

if x==0:
    zero.append(bool(True))
else:
    zero.append(bool(False))

if x==1:
    one.append(bool(True))
else:
    one.append(bool(False))

if x==2:
    two.append(bool(True))
else:
    two.append(bool(False))

if x==3:
    three.append(bool(True))
else:
    three.append(bool(False))

if x==4:
    four.append(bool(True))
else:
    four.append(bool(False))

if x==5:
    five.append(bool(True))
else:
    five.append(bool(False))

if x==6:
    six.append(bool(True))
else:
    six.append(bool(False))

if x==7:
    seven.append(bool(True))
else:
    seven.append(bool(False))

if x==8:
    eight.append(bool(True))
else:
    eight.append(bool(False))

if x==9:
    nine.append(bool(True))
else:
    nine.append(bool(False))

if x==10:
    ten.append(bool(True))
else:
    ten.append(bool(False))

if x==11:
    eleven.append(bool(True))
else:
    eleven.append(bool(False))

if x==12:
    twelve.append(bool(True))
else:
    twelve.append(bool(False))

if x==13:
    thirteen.append(bool(True))
else:
    thirteen.append(bool(False))

if x==14:
    fourteen.append(bool(True))
else:
    fourteen.append(bool(False))

if x==15:
    fifteen.append(bool(True))
else:
    fifteen.append(bool(False))

if x==16:
    sixteen.append(bool(True))
else:
    sixteen.append(bool(False))

I’m not sure what you’re returning from the component. Every time the script runs, you will reinitialise the values of zero,…,sixteen, destroying previous results. If you do just need a one off run each time (lists of length one) I’m sure Grasshopper will have a native comparison component.

To get anything meaningful from this, to store persistent state between different executions, you’ll need to use a GHPython component in SDK mode and put that set up code in the module level, class level or in the component’s __init__, and the main logic code in the RunScript method. Or you can just store the lists as a shared global in sc.sticky. Otherwise in normal script mode, it will overwrite the results each time. But anyway, just use a dictionary:

d = {0 : zero, 1 : one, ..., 16 : sixteen}
for i, num_list in d.items():
    num_list.append(i==x)

Is this what you’re looking for?


16_cull.gh (8.8 KB)

This method worked great and I used the branched structure to remove 15 copies of 12 nodes. Much cleaner.
Thanks!