我需要在python中创建一个二维字典.例如new_dic[1][2] = 5
当我做new_dic = {},并尝试插入值,我得到一个KeyError:
new_dic[1][2] = 5
KeyError: 1
Run Code Online (Sandbox Code Playgroud)
这该怎么做?
def get_children(node):
for child in node['children']:
yield child
for grandchild in get_children(child):
yield grandchild
for line in f:
d = json.loads(line)
child_dic={}
for child in get_children(d):
if child not in child_dic.keys():
child_dic[child["id"]]=1
Run Code Online (Sandbox Code Playgroud)
当我用它来查找json树所具有的子节点数时,我在调用Python对象时得到了一个超出错误的最大递归深度.请帮我一样.