How to find the indices of elements in a list for elements in other list with Python

1 Answer

0 votes
import numpy as np

lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
other_list = [1, 3, 8,]

arr = np.isin(lst, other_list).nonzero()[0]

print(arr)




'''
run:

[0 2 7]

'''

 



answered Mar 20, 2023 by avibootz
...