Identify matching sublists between two lists

dynamo

#1

I feel this should be a basic question, but for the life of me can’t figure out a reliable way to do this - I apologize if this has been answered elsewhere, my searches haven’t seemed to turn up any relevant results so any help would be greatly appreciated.

I have two lists of sublists (list1 and list2) and I would like to identify the matching sublists as their own new lists, as well as the sublists that are in list1 but not in list2 and vice versa. The individual items in the lists are identical, but they may be grouped into the sublists differently, and the sublists may be in a different order.

I have simplified this problem into the example graph below.

It seems as though the List.SetIntersection node does not work in comparing sublists. I have also tried various permutations of List.AllIndicesOf and List.Contains but get bogged down with the different Level and Lacing options.

Thank you in advance for any advice!

Find Matching Lists in Lists.dyn (17.5 KB)


#2

try == and all.true it said when i did a search


#3

Take a look at this:


ind.dyn (24.5 KB)

In the above example…
OUT 1: All elements which are identical between List1 and List2 at the same position within List1.
OUT 2: All elements which do not satisfy the previous condition
OUT 3: All elements from List1 which are also in List2, regardless of position.
OUT 4: All elements from List1 which are not in List2.


#4

Thanks for the reply, Marcel, but I don’t think I’m following you all the way. I’ve tried == and AllTrue in two different ways in the graph below.

The top option uses them with their default settings and does not work.

The bottom option is a step in the right direction by using Cross Product lacing for == and @L2 w/ Keep list structure for AllTrue. It appears to accurately identify that the 0 index of list1 matches the 1 index of list2 ([1,2] == [1,2]), however it seems to give a false positive that the 1 index of list1 matches the 0 index of list2 ([3,4] == [3]). Is there something I’m missing to eliminate the false positives?

Find Matching Lists in Lists.dyn (20.0 KB)


#5

Thanks for the reply, @cgartland. I tried your suggestion on my original input, but it doesn’t seem to work (see below; the top portion uses my original inputs, while the bottom uses the inputs in your example (note the differences in list2)).

Find Matching Lists in Lists3.dyn (55.6 KB)


#6

Oops, the inputs should actually be reversed:

This way, it will test each sublist in List1 against the entirety of List2 and return items in List1 which were found in List2.


#7

Bingo! Thank you @cgartland!! I had discovered the same as you were replying. And by copying & swapping the inputs, I can also get the items in list2 but not in list1. Now I’ll move on to trying to get the last bonus outputs of finding the indices of the matches in each list.

Thank you!

Find Matching Lists in Lists4.dyn (36.1 KB)


#8

I tried using the List.AllIndicesOf node on the original lists with no luck, but you could try to use the same node using the bool output. E.g. given the following list of booleans:

[0] true
[1] true
[2] false
[3] false
[4] true

List.AllIndicesOf(true) would return [0, 1, 4]