I have referred to this post for finding the index(ices) corresponding to a single named element in a list, but have not been able to find an answer to my query among the answers there/documentation.
Specifically: is there a more efficient way than just iterating the method in the link above, for finding the indices corresponding to a set of elements?
Say I have the list
mybiglist=['abc','def','ghi','jkl','mno']
and I want the indices corresponding to 'abc','jkl'
I could do:
mytargetlist=['abc','jkl']
for string in mytargetlist:
print(mybiglist.index('%s' %string))
But it feels like there should be a more efficient way than a loop?
In case the context makes a difference, I am trying to find the indices corresponding to certain vertices in a graph, so that I can use induce_subgraph to create a subgraph containing these vertices. Unfortunately I only know the name labels that I want, and which are attributed to the vertices, and the arguments of induce_subraph are: induce_subgraph(graph, vertex set)