Python Forum
Creating Nested Dictionaries Confusion - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Creating Nested Dictionaries Confusion (/thread-26922.html)



Creating Nested Dictionaries Confusion - gw1500se - May-18-2020

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.


RE: Creating Nested Dictionaries Confusion - Yoriz - May-18-2020

data = {'stoker': {}}
data1 = {}
data1['sensors'] = 'null'
data1.update({'blowers': 'null'})
data['stoker'].update(data1)

print(data)
Output:
{'stoker': {'sensors': 'null', 'blowers': 'null'}}



RE: Creating Nested Dictionaries Confusion - gw1500se - May-18-2020

Great, thanks. I see now what I did wrong and why.