I am beginning to program in python. I want to delete elements from array based on the list of index values that I have. Here is my code
x = [12, 45, 55, 6, 34, 37, 656, 78, 8, 99, 9, 4]
del_list = [0, 4, 11]
desired output = [45, 55, 6, 37, 656, 78, 8, 99, 9]
Here is what I have done
x = [12, 45, 55, 6, 34, 37, 656, 78, 8, 99, 9, 4]
index_list = [0, 4, 11]
for element in index_list:
del x[element]
print(x)
I get this error. I can figure out that because of deleting elements the list shortens and the index goes out of range. But i am not sure how to do it
Traceback (most recent call last):
IndexError: list assignment index out of range