Append list in list of lists
I have a list of lists like this.
lst=[[0, 0.05],
[1, 0.02],
[3, 0.02],
[5, 0.01]]
I want to add the missing lists in the list to get this.
lst=[[0, 0.05],
[1, 0.02],
[2, 0.01],
[3, 0.01],
[4, 0.005],
[5, 0.005]]
Here, [2,x2] added between [1,x1] and [3,x3] and x2=x3/2 and x3=x2 is performed. Same is to be done for [4, x4].
I have tried this.
for i in range(len(lst)):
if lst[i][0]!=i:
lst1=[]
lst1.append(i)
lst1.append(lst[i+1][1]/2)
lst.append(lst1)
This code is unable to keep track of the element being iterated and adds duplicates and wrong values.