Python list comparison

While comparing a list of hundred distances to one distance, the < only gives one true or false.
My goal is to select the indexnumbers/items within the given range of z.

python list comparison 01.gh (13.9 KB)

Hi Edward,

the x variable comes in a s a list, so you need to itterate through it’s values and compare each value individually
see this quick hack where I use the print output to dispach the points:

-Willem

1 Like

For the next step I could also use for in range again. However, itemgetter is another option. In sublimetext it works when I replace the list of indices with numbers, but it would not work with a list.
I think I implement it wrong.
python list comparison 02.gh (15.4 KB)

Hi Edward,

I’m not familiar with itemgetter, but my take would be:

import rhinoscriptsyntax as rs
from operator import itemgetter


emplist = []
emplist.append(y[0])
b = rs.AddCircle(y[-1],z)



distances = []
dispatch_smaller = []
dispatch_equalorlarger = []

#handle everything in one for loop
for i,xval in enumerate(x):
    dist = rs.Distance(y[-1],xval)
    if (dist<z):
        dispatch_smaller.append(x[i])
    else:
        dispatch_equalorlarger.append(x[i])


a = dispatch_smaller
b = dispatch_equalorlarger

-Willem

1 Like