I have a problem which is similar to this.
Here I am trying to append 0 after every 5 in the list.
The below code does not update the length of the list and the output I get is [1,4,5,0,2,7,5,0,5]
while desired output is [1,4,5,0,2,7,5,0,5,0]
mylist1 = [1,4,5,2,7,5,5]
for i in range(len(mylist1)):
if mylist1[i] == 5:
mylist1.insert(i+1,0)
print(f'output: {mylist1}')
I have to update in the same list mylist1.