# 'Exact' list comparison

I may be overthinking this but regardless, I’m stuck.

I’m trying to compare 2 lists but I want to compare them for an exact match and report anything that doesn’t match. Using Set Intersection I can get items that are missing but this won’t report unintended duplicate items.

Is there a way to compare values but once a value has been ‘used’ not use it again? List sequence isn’t necessarily consistent either just to complicate matters.

The sample script attached shows at a very basic level what I’m trying to do - but for the lower Set Intersection I’m wanting it to show 1 and 3 (1 missing 3 additional).

I suspect this will be another reason to learn :Python but other stuff just keeps getting in the way!!

Hello Keith

Try this

``````# Enable Python support and load DesignScript library
import clr
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

a = IN[0]
b = IN[1]
# Place your code below this line

t = b

x=[]
for i in a:
for j in b:
if i == j:
t.remove(i)
x.append(i)

p = a
for i in x:
for j in a:
if i == j:
p.remove(j)

for i in p:
t.append(i)

# Assign your output to the OUT variable.
OUT = t
``````

@Nico_Stegeman - thanks this is definitely moving towards what I’m after (and indeed ticks the box of my original question!).

I’m keen to try and get my head around some of Python at least and this could be a good starting point. I can understand some of what’s happening but not all - could you help take me through it?

first question would be why does the first bit of code ignore the additional equal values? If I ran a == node in Dynamo for example it would return all that are true. Also how does ‘lacing’ work in Python code?

``````x=[]
for i in a:
for j in b:
if i == j:
t.remove(i)
x.append(i)``````

Hello Keith

Forget the first post. Won’t work in every situation

Try this

``````# Enable Python support and load DesignScript library
import clr
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

a = IN[0]
b = IN[1]
# Place your code below this line

t = []
for i in b:
t.append(i)

x=[]
for i in a:
for j in b:
if i == j:
t.remove(i)
x.append(i)
break

p = []
for i in a:
p.append(i)

for i in a:
for j in b:
if i == j:
p.remove(i)
break

for i in p:
t.append(i)

# Assign your output to the OUT variable.
OUT = sorted(t)
``````

Hello Keith

A little explanation :

Nico

1 Like

@Nico_Stegeman many thanks! I’m going to go and have a play around with that and see if I can create it again. I think doing a bit of list management with Python will be a very good place to start.

thanks for taking the time, it’s much appreciated.