-3

I have a list of values for example:

[1,2,3,4,5,6,7,8,9,10]

And specific indexes like:

[0,3,5]

I want something that returns deleting the values which the index belongs to the [0,3,5] array:

[2,3,5,7,8,9,10]

Any ideas for Python 3? Thanks

Miguel Santos
  • 1,806
  • 3
  • 17
  • 30

1 Answers1

0

Using enumerate and list comprehension.

Ex:

l = [1,2,3,4,5,6,7,8,9,10]
toDelete = [0,3,5]

print([v for i,v in enumerate(l) if i not in toDelete])

Output:

[2, 3, 5, 7, 8, 9, 10]
Rakesh
  • 81,458
  • 17
  • 76
  • 113