1

I have a method which requires being able to add multiple nested dictionaries at once.

For example:

mydict = {}
mydict['subdict']['subdict2'] = {'this': 'is what i want'}

How can I do this?

mkrieger1
  • 14,486
  • 4
  • 43
  • 54
aanginer
  • 100
  • 8
  • 1
    Looks like duplicate question! Please do check - https://stackoverflow.com/questions/16333296/how-do-you-create-nested-dict-in-python – sam Mar 22 '22 at 22:09

1 Answers1

0
from collections import defaultdict
mydict = defaultdict(dict)
mydict['subdict']['subdict2'] = {'this': 'is what i want'}
Andrey
  • 388
  • 2
  • 8