Python Script Exact String

Hello everybody,

i am trying to apply a Python Script to a dynamo graph that creates an integer based on a text parameter. The problem is that some of the elements i am using have a text parameter called “rentable” while other have a text parameter called “not rentable”. Dynamo creates the same integer for both strings (maybe because both contain the word “rentable”?)

list = IN[0]
newlist =

for x in list:
if “rentable” in x:
newlist.append(1)
elif “not rentable” in x:
newlist.append(2)
else:
newlist.append(3)

OUT = newlist

Thanks!

This is pretty easy with design script in a code block:

A == “Rentable” ? 
1 : 
A  == “Not Rentable” ? 
2 : 
3 ;
2 Likes

Try
if x==“rentable”:
newlist.append(1)

2 Likes

Yup, in basically means “can be found in”. It will search for items in a list or substrings within a string, so you have to be careful how you use it. As the others have mentioned you’ll want to check if the string “is equal to” (==).

The other option is to flip your logic:

if “not rentable” in x:

elif “rentable” in x:

2 Likes

Thank you very much guys, its working perfectly now!

I think using “==” Dynamo node should be enough. Don’t need to code :smiley: