I'm trying to obtain indexes of one list based on elements of another list.
Let's say I have:
list1 = [1, 2]
list2 = [1, 2, 2, 3]
I want to obtain indexes of list2 that match elements from list1:
>>> [0, 1, 2]
Is there any one liner that can do it? Thank you for any suggestions.
EDIT: Current multiple line solution:
list1 = [1, 2]
list2 = [1, 2, 2, 3]
matched = []
for i, e in enumerate(list1):
for j, f in enumerate(list2):
if e == f:
matched.append(j)
>>> [0, 1, 2]