Compare a number list with float input

Hello,
this might be a very simple and stupid question, but I’m new to using Python within Grasshopper (using Python in general, I do have some basic understanding, but used a different language before).
I wanted to sift a given list of decimal numbers (values coming from the Elefront component) by boundary numbers. E.g. if my list contains (1.1 , 1.6 , 0.8 , 2.4) and my boundaries are 1.0 and 2.0, it should do:
below 1.0: add 0 to sift pattern
between 1.0 and 2.0: add 1 to sift pattern,
above 2.0: add 2 to sift pattern.
So the example above should create a patterns like this (1 , 1 , 0 , 2)
To be more in charge of what numbers are my boundaries, I didn’t want to hard code them all into the Python script, but rather be able to adjust them within Grasshopper. That’s why I created these additional inputs. But for some reason, everything gets sorted into the last group of my sift pattern (shown in the Panel on the right bottom - there shouldn’t be 4 everywhere).
I thought, converting the inputs to float might help, but it didn’t. So now I’m a little lost where this error occurs. Does anyone knows anything?

Best,
Carina

PS: I’m sure, there is a more efficient way to code this. Right now I’m trying to reach the state of ‘it works so far’. :sweat_smile: I’m still grateful for coding advise!

Dear Carina

you may want to use the type hint of the input parameter.
right click on the input-parameter-Text of the (closed) script component and set the needed type. (float or int)

in your code - the casting you re doing in the section / after
# funktionen
will not work - you have to write the casted values back to the array:

numStr = ["1.1","2.2","3.3","4.4"]
print(numStr)
for i in range(len(numStr)):
    numStr[i] = float(numStr[i])
print(numStr)

['1.1', '2.2', '3.3', '4.4']
[1.1, 2.2, 3.3, 4.4]

if this does not help - please post your .gh file

kind regards -tom

Thanks Tom, writing the casted values back to the array works wonderfully! :smiley: