I have a list of the form L = [1, 2, 3, 4, 1, 2, 1, 3, 0, 4] and I want to remove the third index where 1 occurs and replace it with 0. My code is this, but this removes the previous indexes of 1(1st and 2nd also) which I want in my List. My code is this
counter=0
index = 2
L = list([1, 2, 3, 4, 1, 2, 1, 3, 0, 4])
print("Value before is\n", L)
for i in range(len(L)):
y=L.index(1)
print(y)
if(counter==index):
L[y]=0
break
else:
counter=counter+1
L[y]
print("Value of list in else\n",L)
print("Value of counter\n",counter)
print("After the value is\n",L)
So output comes as
[2, 3, 4, 2, 0, 3, 0, 4]
but I want it as
L = [1, 2, 3, 4, 1, 2, 0, 3, 0, 4]
and remember that I will not be given directly the index which I want to change
So I could Do L[7]=0
Thanks in advance