Suppose we have two lists
list_A = [1,3,4,54,3,5,6,2,6,77,73,39]
list_B = [0,3,2,8]
I want to access elements of list_A that have the values in list_B as their indices (without using loops).
After implementing it, the result should be as follows for the above case:
[1, 54, 4, 6]
Is there any easy method to do this without bothering with for loops (calling it explicitly in the code) ?
for-loop. The obvious way to do it is with a list comprehension. Does[A[x] for x in B]use afor-loop? Maybe. Doesmap(lambda i: list_A[i], list_B)? Nofor-loopin sight, but there is iteration inmap. How about numpy solutions? No iteration visible, but ...