I have 2 lists:
l1 = ['oak', 'tree', ',', 'tree', 'preservation', 'order', 'to', 'be', 'crowned', 'and', 'cleared', 'of', 'deadwood'] l2 = ['tree', 'preservation', 'order']
I need to find indices of intersection of these. Result should be just a list of[3,4,5]
.
The problem is algorithms I found returns wrong values. For example:
def find_matching_indices(a, b):
for i, x in enumerate(a):
for j, y in enumerate(b):
if x == y:
yield i, j
returns [(1, 0), (3, 0), (4, 1), (5, 2)]
so it consideres all matches not the whole list within list.