In Python, how do I index a list with another list?
indexing, list, python
Solution
T = [L[i] for i in Idx]
Problem
I would like to index a list with another list like this ``` L = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] Idx = [0, 3, 7] T = L[ Idx ] ``` and T should end up being a list containing ['a', 'd', 'h']. Is there a better way than ``` T = [] for i in Idx: T.append(L[i]) print T # Gives result ['a', 'd', 'h'] ```