Python Forum

Full Version: Creating Nested Dictionaries Confusion
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm afraid I am not understanding dictionaries. After reading various articles the only thing I learned is I don't know what I am doing. To start, I am trying to produce this json structure.

Output:
{"stoker":{"sensors":null,"blowers":null}}
Here is the code I can't get right:
data={'stoker':{}}
data1['sensors']='null'
data1.update('blowers','null')
data['stoker'].update(data1)
I cannot figure out the syntax for nesting the 2nd dictionary (date1). Can someone give me a brief tutorial? TIA.
data = {'stoker': {}}
data1 = {}
data1['sensors'] = 'null'
data1.update({'blowers': 'null'})
data['stoker'].update(data1)

print(data)
Output:
{'stoker': {'sensors': 'null', 'blowers': 'null'}}
Great, thanks. I see now what I did wrong and why.