Comparing two lists and counting similarities

I’m having trouble with this (seemingly) simple list comparison I need to make. Maybe I’ve just been staring at the values too long and twisted myself up. Anyways, I want to compare List A with List B’s level 2, index 0 values. I.e. I want to compare:

{“G-0”,
“A-0”,
“A-0”,
“AD0”}

with:

{“G-0”,
“C-0”,
“A-0”,
“P-0”}

and I want to increase List B’s level 2, index 1 values by 1 each time there is a match for that string. So that my final result will be:

{{“G-0”,2},
{“C-0”,1},
{“A-0”,3},
{“P-0”,1}}

See image below. Of course, the lengths of these lists will not always be these lengths, so I’m trying to find an adaptive solution that could handle multiple list lengths. However, the list levels and organization will remain the same.

Any help is appreciated, I’ll post my progress as I keep working.

Thanks, everyone!

Hi @calvertnr

Flatten both list by using OOTB Flatten node -> List.GroupByKey -> List.Count lacing to longest will get you started.

@Kulkul
Not sure if this is exactly where you were going, but this seems to work. There are probably some tweaks that would make it more efficient.