Compare if the elements from one list exist in another

Hello Everybody,

I would like to compare if the elments of one list exists in another one.
¿Is there any function or node or way for it?

1 Like

It means you want to check whether the element of this list exists in another list ?

Yes that is the idea

You can use Python script to do it. I suggest using dictionary data structure because it will be faster to check if the element exists in the list or not (O(1) comparing to O(n) if we use array instead of dictionary).


Thank you mrkevinht91 . I will try it

Hi Asier,

Python is always a good option. If you are not comfortable with it, here’s some nodes :

1 Like

Sorry mrkevinht91 I have tried the python solution but it is appearing the following Warning and error:

Do you know what can it be ?

Thank you very much for your help

Hello jonathanatger
I have tried with the nodes that you show in the picture but i have problem with the List contains node. It is not comparing all the elements.

Do you know what can the problem be ?

Thank you very much for your help

look at the lacing. and you should show what you typed inside the python script. not just show the shell…

I have added to the image the code inside the node.

What stillgotme points out, is that you need to set the lacing likewise :


This way the node performs the check for each item of the first list against each item of the second.

1 Like

To help you with this question, your x and X are of different capitalization. thats all.

That’s the first error.

But the Warning showing up is about the libraries. It is needed to add a path to the System library, this should do the trick (to be put after ‘import sys’ line 3) :

pyt_path = r'C:\Program Files (x86)\IronPython 2.7\Lib'

Maybe you don’t install python yet ? Could you try this one instead:

1 Like

Dynamo has a great OOTB node for this: SetIntersection



Yes, I have alredy installed python. I think it was not able to find the path. After addiing that code, it works perfectly:

I leave the code just in case someone wants it:

import sys
pyt_path = r’C:\Program Files (x86)\IronPython 2.7\Lib’
import clr
from Autodesk.DesignScript.Geometry import *

from collections import Counter
list1 = IN[0]
list2 = IN[1]
x = Counter(list1)
result = [ ]
for each in list2:
if each in x:

OUT = result

For the code of the last image. It is appearing the following warning:


you are missing “:” at line 7. It should be:
for each in set(list1):

1 Like

With the correction it works perfect. Thanks mrkevinht91

1 Like

Hello Everyone, yeah, for two lists, it does works perfectly.

I have two Value
V1 = 0.5
V1_list = [V1-0.01, V1-0.04]
V2 = 0.49
I have a list which is [V1-0.01, V1-0.04]
I need to check whether V2 exists in V1. I mean in the list or no
Anybody could help, please.