If condition in Python


#1

Hi All,

I want to filter the walls by the thickness and name. So I have written this code in Python, i think the reason why its not working, is the fact that i combine two lists. Can somebody have a look and tell me what I am doing wrong and how it can be solved.

Tnx in advance,

Rasa


#2

the second loop should start from 4 space from the first loop , like this :

for x in range …
____for i in range …
________if etc …


#3

Thank u for replying. I saw that also and fixed it. still it does not work. I think that naam[x].contains(“werk”);_ is the problem



#4

try changing and name[i].contains(“werk”): to:
and “werk” in name[i]:


#5

I don’t get an error, but it does not work. ides 8 should be true


#6

I think it’s looping over too many times, try this instead:

OUT = [True if x>100 and x<200 and "werk" in i else False for x,i in zip(dikte,naam)]

#7

Still nothing. :frowning:


#8

try:

test=[]
for x,i in zip(dikte,naam):
	if x>100 and x<200 and "werk" in i:
		test.append(True)
	else:
		test.append(False)`

OUT = test

Can you show the preview of the Element.GetParameterValueByName node?


#9

Tnx, this works great. Could you explain why this one worked and what i did wrong?
Still trying to learn Python


#10

Both of them worked, if you didnt managed, then some other error must have been made.

in addition you could do it as a definition

def GetWerk(dikte, naam, t=[]):
    for x, i in zip(dikte, naam):
        if x > 100 and x < 200 and 'werk' in i:
            t.append(True)
        else:
            t.append(False)
    return t

OUT = GetWerk(IN[0], IN[1])

Home.dyn (3.9 KB)