Another option:
>>> numbers = [2, 6, 12, 20, 24, 40, 42, 51] >>> indicies = [2, 4, 5] >>> offset = 0 >>> for i in indicies: ... del numbers[i - offset] ... offset += 1 ... >>> numbers [2, 6, 20, 42, 51]
Edit:
Therefore, being hopelessly mistaken in this answer, I compared each of the different approaches:

The horizontal axis is the number of elements, the vertical axis is time in seconds.
The quickest option is to use slicing to create a new list (from @gnibbler):
def using_slices(numbers, indices): result = [] i = 0 for j in indices: result += numbers[i:j] i = j + 1 result += numbers[i:]
It's amazing that he βinstallsβ (@ Eric) to beat numpy.delete (@Jon Clements)
Here I used the script , maybe I missed something.
source share