How does python generate a nested dictionary? I don't want to use defaultdict implementation.

such as native dict attribute

test=dict()
test["a"]=1         -sharp 
test["x"]["y"]=2    -sharp 

I want to generate a recursive dictionary. If you don"t have this key, create it. Which method can be simpler and more elegant? thank you

Sep.30,2021

there will be some problems.
test ["x"] ["y"] is equivalent to a chain call. First get test ["x"] , and then assign to ["y"] this key. When you take the first step, you can't get whether you want to assign values later. You can only create keys that don't exist every time you getitem.
what type of key is created? The default is dict, of course, but if his y position is an integer, do you want to create a list?
you have to consider all these.
finally is a simple implementation. Do not consider the case of list at all.


:

test=dict()
test['a']=1
x = {"y":2}         
test['x'] = x   
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b317fb-2bdb1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b317fb-2bdb1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?