I’m sure I am missing something very simple, but I am having trouble processing a list using a Python script.
I have a list of values ranging from 1 to 1000, that I want to process to give me a list of new values.
I am calling the input list ‘x’ and the output list ‘y’. The way I want to process is that if x<75 I want y=5, if 75<=x<200 I want y=10 and so on. What I have shown below works correctly for a single input, but does not process a list.
There are probably easier ways to do what I want, but any suggestions?
you are indeed. Your code only works on a singleton (i.e. one object, or in your case, a number). As you want to provide a list you need to store your result in a list and iterate over the input list. One method is a simple loop to iterate through the list (and python has some pretty powerful built-in itertools which you should check out on python.org which are more efficient than loops):
from Autodesk.DesignScript.Geometry import *
#The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN
numberList = IN
y = 
for x in numberList:
if x < 75:
elif 75 <= x < 200:
elif 200 <= x < 500:
elif 500 <= x < 800:
#Assign your output to the OUT variable.
OUT = y