There is a method in the lists indexthat you can use.
>>> nameArr = ['josh','is','a','person']
>>>
>>> map(nameArr.index, ['a', 'is'])
[2, 1]
>>>
>>> [nameArr.index(x) for x in ['a', 'is']]
[2, 1]
BTW, indexinvokes ValueErrorif the item is not in the list. Therefore, if you want to provide non-list items to the index method, you may need to handle the error properly.
source
share