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
  • 19,194
  • 5
  • 54
  • 65
aanginer
  • 120
  • 2
  • 10
  • 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
  • 400
  • 2
  • 8