Filter group of lists to one list containing X value - multiple X values in another list

I have list A is a list of lists that looks something like this:

0 - 
    0 - A
    1 - Other info
1 - 
    0 - B
    1 - Other info
2 - 
    0 - C
    1 - Other info

I have list B is a flat list that looks like this:

0 - A
1 - C

What I need to do is iterate over list B and find its matching list of information in list A.
So, the indices would match like:
B → A
0 → 0
1 → 2

I’d want a third list, C, that contained indices 0 and 2 from list A:

0 - 
    0 - A
    1 - Other info
1 - 
    0 - C
    1 - Other info

Hi @TheMattatonAP ,

Like this?

1 Like

Yes, that looks just like it should work, but I’m only getting a match on the second item in list B for some reason. I have longest lacing set up on the == as you do. I don’t get why it’s not matching. Index 11 should be true.

@EdsonMatt
Second Test with more items in list B in a different order. Always uses the last item. 3, 10, and 11 should be true.
If I do a simple test with mock lists like your example with the same list structures, it works. This makes no sense to me.

I think it’s because the order of the elements in list B doesn’t match with the order of elements in list A. Assuming the values in list B are unique in list A as well, you can try “List.IndexOf”. If it’s not, try to use “AllIndicesOf” instead of “List.IndexOf”. Make these changes and see if it works.

Here’s another approach using python, in case you’re interested in:

listA  = IN[0]
listB  = IN[1]
listC  = []

for itemB in listB:
	for sublist in listA:
		if itemB in sublist:
			listC.append(sublist)
		
OUT = listC
1 Like

That worked! Thanks!