I have a problem statement where i have to fill the missing values ("_") in a specified way.
Example
Input:- ",,30,,,,50,,_" Output:- 10,10,12,12,12,12,4,4,4
How it is getting filled? we will fill the missing values from left to right a. first we will distribute the 30 to left two missing values (10, 10, 10, _, _, _, 50, _, _) b. now distribute the sum (10+50) missing values in between (10, 10, 12, 12, 12, 12, 12, _, _) c. now we will distribute 12 to right side missing values (10, 10, 12, 12, 12, 12, 4, 4, 4)
My code is as below
s = "_,_,30,_,_,_,50,_,_"
s = s.split(",")
print(s)
print('***********')
result = []
count = s.index('30') + 1
print(count)
print('****************')
value = int(s[2]) / count
while count > 1:
result.append(str(int(value)))
count -= 1
value = int((value + int(s[6])) / (6 - 2 + 1))
count = 6 - 2 + 1
while count > 1:
result.append(str(value))
count -= 1
value = int(value / (len(s) - 6))
count = len(s) - 6
while count > 0:
result.append(str(value))
count -= 1
print(result)
Only problem is here i am making things hardcoded, so instead of 30/50 if there are any other numbers my code is not going to work. So can someone help me to fix this hard coded part.