小编Sau*_*abh的帖子

在python中声明一个多维字典

我需要在python中创建一个二维字典.例如new_dic[1][2] = 5

当我做new_dic = {},并尝试插入值,我得到一个KeyError:

new_dic[1][2] = 5
KeyError: 1
Run Code Online (Sandbox Code Playgroud)

这该怎么做?

python dictionary

40
推荐指数
5
解决办法
7万
查看次数

json树中超出了最大递归深度

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对象时得到了一个超出错误的最大递归深度.请帮我一样.

python json

3
推荐指数
1
解决办法
3336
查看次数

标签 统计

python ×2

dictionary ×1

json ×1