List.Contains node

Hi,
I am trying to extract the element and material details from the excel spreadsheet, and compare it with the existing model elements to set parameter to the selected element. I wanted to check the list using list.contains node before setting the parameter value. But, I am not sure what is wrong with my script, I am getting false outputs.

I tried manually entering the element name, it works. But, I would like to know the mistake with my first method.

Any help is appreciated.
Thanks

Change the Lacing to Cross Multiply and then look for TrueForAny or AnyTrue nodes.

Hi, I tried to change the lacing to Cross Product for the List.Contains node. But, still the same.

Well in this configuration you don’t need the Level on the Contains node, nor the cross product.

Another way to do it would be to use the == node since they are strings.

Actually, I tried that way too. But, I had the same issue, the output was false.

Are there any extra characters like spaces maybe in either Values?

Maybe check by taking a single item and compare with == to another single value.

There are no special characters. But I tried to copy the element name from the spreadsheet and tried in two different ways, one using the string node and other using the basic code block. In the first case, answer is false, but the second case gives me the right answer. I am wondering what’s the difference between the two as both the values is copied from the same file.

1 Like

Could be a syntex issue? did you write well?

Yes, I did.

I tried this! and then it is not working!
Can write in one line without “enter”

I am not pressing enter. I am trying to type in a single line, but when I finish it automatically splits the word. I tried to upload a snippet, but I couldn’t because of the file size.

Hi, The problem was with the excel file. I was able to resolve the issue.
Thanks, both for your replies.

Hi,
I know this may be a bit late but just wanted to discuss intersecting lists of different lengths.
Hope this is something that can help someone get to the desired list quicker.

These are the 4 ways I found you can do this depending on what you need.

a = IN[0]
b = IN[1]
d = []
#intersect and keep duplicates
for i in a:
	for j in b:
		if i == j:
			d.append(j)
			
#intersect and exclude duplicates	
c = (set(a) & set(b))


#find intersection of list1 and list2 and exclude duplicates
intersection_set = set.intersection(set(a), set(b))
intersection_list = list(intersection_set)


OUT = c,d,intersection_list