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']
L[idx]doesn't just work in base Python. Zen of python and all that. In numpy, things like this work just fine.L[idx]did do this in base Python. In fact, I can quote the Zen of Python to support that: "Special cases aren't special enough to break the rules."L[idx]does "work" - it means that the tuple(0, 3, 7)will be supplied as an index, which will subsequently cause aTypeError. It would work fine with, say, a dict using tuples for its keys. (Slices are different, in that - in prehistoric times - they were a special syntax before there was aslicetype.)