For the list k1=[31.0, 72, 105.0, 581.5, 0, 0, 0], I would like to add a constant for example 100 to the first non-zero element in the reverse list. this is what I want: newk1=[0, 0, 0, 681.5, 105, 72, 31] As a beginner in Python I could not figure it out. Could you please help me. That is my code:
k1=[31.0, 72, 105.0, 581.5, 0, 0, 0]
Inverselist=[]
for i in range(len(etack1)):
Inverselist.append(etack1[-(i+1)])
print("Inverselist", Inverselist)
newk1=Inverselist
run_once = 0
while run_once < 1:
for j in range(len(newk1)):
if newk1[j-1]>0:
newk1[j-1]=newk1[j-1]+100
run_once = 1
break
print("Newk1", newk1 )