python嵌套字典:从集合中OrderedDict

2024-03-28 19:14:19 发布

您现在位置:Python中文网/ 问答频道 /正文

如何嵌套医嘱信息?

我试过:

table=collections.OrderedDict()
table['E']['a']='abc'

但这显示出了错误。

我也试过:

table=collections.OrderedDict(OrderedDict())
table['E']['a']='abc'

这也显示了错误。

我试过:

table=collections.OrderedDict()
table['E']=collections.OrderedDict()
table['E']['a']='abc'

这很管用。

在我的编码中,我不得不这样使用:

table=collections.OrderedDict()
for lhs in left:
    table[lhs]=collections.OrderedDict()
    for val in terminal:
        table[lhs][val]=0

效果很好。但是还有其他方法吗。当我读到python时,它会自动管理它的数据结构。

不管怎样,是否可以声明一个字典,以及它将有多少嵌套,以及它的嵌套在一行中的数据结构是什么。

使用一个额外的循环来声明一个字典,感觉好像我在python中遗漏了一些东西。


Tags: in信息声明数据结构编码for字典错误