嵌套字典 - 类?

时间:2018-03-26 08:31:32

标签: python dictionary

我目前正在使用Python配置解析器,在这种情况下,我需要构建一个嵌套字典。首先,我尝试了常用的"功能",但现在,我正在寻找一个带方法的课程。

我的想法:

Class Dict
-var dict_test => {}
- method level_up(key, value={})
- method level_down(key, value={})
- method current_add(key, value={})

d = Dict()
print(d.dict_test) => {}

d.level_up("Test1","Value1")
print(d.dict_test) => {{"Test1": "Value1"}}

d.current_add("Test2")
print(d.dict_test) => {{"Test1": "Value1", "Test2": {}}}

d.level_up("Test3")
print(d.dict_test) => {{"Test1": "Value1", "Test2": {"Test3", {}}}}}

d.level_up("Test4","Value4")
print(d.dict_test) => {{"Test1": "Value1", "Test2": {"Test3", {"Test4","Value4"}}}}}

d.level_down("Test5","Value5") 
print(d.dict_test) => {{"Test1": "Value1", "Test2": {"Test3", {"Test4","Value4"} "Test5": "Value5"}}}

d.level_down("Test6","Value6") 
print(d.dict_test) => {{"Test1": "Value1", "Test2": {"Test3", {"Test4","Value4"} "Test5": "Value5"}, "Test6": "Value6"}}

问题:这种类存在吗? 我试图发展这种需求,但我的技能还不够。

0 个答案:

没有答案