Identify matching sublists between two lists

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)
Find%20Matching%20Lists%20in%20Lists

2 Likes

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

Take a look at this:

image
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.

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)

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)

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.

2 Likes

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)

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]