let's say I am trying to delete the elements of a list in python that belong to even indexes like this:
q=int(input("cate elemente sa aibe lista?\n"))
l=[int(input()) for i in range(q)]
list_indexes=[]
#while len(l)!=1:
for i in range(len(l)):
if i % 2 == 1:
list_indexes.append(i)
for i in list_indexes:
del l[i]
print (lista)
My error says that:
line 11, in <module>
del l[i]
IndexError: list assignment index out of range
I've been trying to debug it and i
shouldn't be out of range and it seems like I am repeating this mistake in other examples of code as well. Can somebody explain to me what am I doing wrong so that I won't repeat it please? I know there are simpler ways to do this exercise but I want to learn what is my mistake here.
Many thanks!