Difference of Lists

Hi all,

I am trying to find the difference between 2 lists. I have the following dyn script as in screen capture and Python implementation of the logic used to find the difference.

Logically it is looking fine to me but it seems I am missing something quite obvious. If you look at the 2 lists, from the first sublist I should have only 3 points as the rest are common in both of them.

I am attaching the dyn snap as well as the code for the new list. Any help or suggestion would be much appreciated.

chain1 = IN[0]
chain2 = IN[1]

result = list()
for i in range(len(chain1)):
	inner = [chain for chain in chain1[i] if chain not in chain2[i]]
	result.append(inner)
	
OUT = result

Points are notoriously bad at comparing due to internal rounding. Try converting them to strings before comparing.

That being said, the List.SetDifference node already does what you’re after.

1 Like

@ab.chakraborty ,

can you use also SetIntersection.

or this


KR
Andreas

@Nick_Boyts I tried using the List.SetDifference but came up with the same result. Will try after converting them to strings.

Point.PruneDuplicates can also help here - in the loop: append the item to the front of the list, prune duplicates, remove the first item.

Not sure if this would be faster than string conversion and back though.