How to add value to a key which is within dict and array
dict1 = {'result':[{'key1':'value1','key2':''}]}
Like to add value to key base on the result. Example:
`{‘result’:[{‘key1’:value1,‘key2’:value2}]} ```
Will this work?
dict1['result']['key2'] = value2
What happened when you tried?
And no it will not work, because key2
is not in a dict that is part result
directly, but part of a list that part of the dict, so it should be
dict1['result'][0]['key2'] = 'value2';
0 being the 0th element of the list dict['result']
system
Closed
3
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.