Python Forum
Creating Nested Dictionaries Confusion
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Nested Dictionaries Confusion
#1
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.
Reply
#2
data = {'stoker': {}}
data1 = {}
data1['sensors'] = 'null'
data1.update({'blowers': 'null'})
data['stoker'].update(data1)

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a list of dictionaries while iterating pythonnewbie138 6 3,196 Sep-27-2020, 08:23 PM
Last Post: pythonnewbie138
  Searching through Nested Dictionaries and Lists Dave_London 1 6,287 Jul-09-2020, 03:36 PM
Last Post: mrdominikku
  creating a list of dictionaries from API calls AndrewEnglsh101 5 3,013 Apr-03-2020, 02:21 PM
Last Post: AndrewEnglsh101
  Finding value in nested dictionaries with lists mart79 16 7,752 Mar-08-2020, 08:16 PM
Last Post: ndc85430
  nested dictionaries to CSV mart79 9 12,308 Jul-29-2019, 04:59 AM
Last Post: mart79
  Transform simplified dictionary to nested dictionaries bhojendra 1 2,324 Jul-02-2019, 02:05 PM
Last Post: ichabod801
  creating an 'adress book' in python using dictionaries? apollo 6 14,693 May-06-2019, 12:03 PM
Last Post: snippsat
  Help to flatten list of nested dictionaries shawbapmp 4 5,625 Feb-25-2019, 10:18 PM
Last Post: shawbapmp
  Nested Dictionaries with Lists BriHaug 1 45,923 Feb-23-2019, 02:10 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020