[Solved] How to delete elements from a list using a list of indexes? [duplicate]


You can use enumerate together with a conditional list comprehension to generate a new list containing every element of my_list that is not in the index location from to_delete.

my_list = ['one', 'two', 'three', 'four']
to_delete = [0,2]

new_list = [val for n, val in enumerate(my_list) if n not in to_delete]

>>> new_list
['two', 'four']

1

solved How to delete elements from a list using a list of indexes? [duplicate]