Concise way to remove elements from list by index in Python
optimization, python
Solution
If you wanted to, you could use `numpy`.
import numpy as np
myList = ['a','b','c','d']
toRemove = [0,2]
new_list = np.delete(myList, toRemove)
Result:
>>> new_list
array(['b', 'd'],
dtype='|S1')
Note that `new_list` is a `numpy` `array`.
Problem
I have a list of characters and list of indexes ``` myList = ['a','b','c','d'] toRemove = [0,2] ``` and I'd like to get this in one operation ``` myList = ['b','d'] ``` I could do this but is there is a way to do it faster? ``` toRemove.reverse() for i in toRemove: myList.pop(i) ```