I have a dictionary that contains a list capex in which there is one value. The basic structure of that dictionary is:
outputDic = {
"capex": [{
"value": 450000,
"start": 5,
"year": 10
}]
}
value, start, and year are just the random numbers but there is decider variable which will basically decide how many values will be there in the list. So let just say if decider is 2 then there will two values and if it is 3 then there will be three values in the list and so on.My approach:
outputDic = {
"capex": [{
"value": 450000,
"start": 5,
"year": 10
}]
}
decider = 2
for i in range(1, decider):
outputDic['capex'][i]['value'+str(i)] = 40*i
outputDic['capex'][i]['start'+str(i)] = 20*i
outputDic['capex'][i]['year'+str(i)] = 10*i
print(outputDic)
It gives an error of List out of index and that may be because there is only one element in the list. My expected output is:
decider = 2
outputDic = {
"capex": [
{
"value": 40,
"start": 20,
"year": 10
},
{
"value": 80,
"start": 40,
"year": 20
}
]
}
Can anyone please help?