I am trying to update same dictionary keys at different index in a list using a for loop. I am not sure if this is even an allowed format/way to do that with python code. Any help will be greatly appreciated.
rc_description_final=["Apple","Orange", "Pineapple"]
rc_action_final = ["Red", "Fruit", "Yellow"]
k=0
while k < len(IDs):
temp={}
rc = {}
temp['Rate'] = [rc]
d = 0
print(rc_description_final)
print(len(rc_description_final))
while d < len(rc_description_final):
temp['Rate'][d]['Description'] = rc_description_final[d]
temp['Rate'][d]['Action'] = rc_action_final[d]
temp['Rate'].append(rc)
d = d + 1
json.dumps(temp)
print(json.dumps(temp))
k = k + 1
I expect the output as:
{
"Rate Limits": [
{
"Description": "Apple",
"Action": "Red"
},
{
"Description": "Orange",
"Action": "Fruit"
},
{
"Description": "Pinapple",
"Action": "Yellow"
}
]
}
But I am getting the output as:
{
"Rate Limits": [
{
"Description": "Pinapple",
"Action": "Yellow"
},
{
"Description": "Pinapple",
"Action": "Yellow"
},
{
"Description": "Pinapple",
"Action": "Yellow"
}
]
}