How to find indices of first two elements in a list that are any of the elements in another list?
story = ['a', 'b', 'c', 'd', 'b', 'c', 'c']
elementsToCheck = ['a', 'c', 'f', 'h']
out = []
for i, v in enumerate(story):
if v in elementsToCheck:
out.append(i)
if len(out) == 2:
break
print(out)
Prints:
[0, 2]
Possibly the shortest way to implement this:
[i for i, x in enumerate(story) if x in elementsToCheck][:2]