简体   繁体   English

将新值更新为字典中的键(python)

[英]update new value to key in dictionary (python)

I make a minimised DFA, to use key value style coding, I used dictionary. 我做了一个最小化的DFA,使用键值样式编码,我使用字典。

so there is a dictionary, 所以有一本字典,

{1: {1:2}}

I want to update this dictionary add 2:3 to add key 1's dictionary. 我想更新这个字典添加2:3添加键1的字典。

{1: {1:2, 2:3}}

I don't know how to do this. 我不知道该怎么做。

Is any simple idea to solve this? 有什么简单的想法来解决这个问题?

you can use update() : 你可以使用update()

In [27]: dic={1: {1:2}}

In [28]: dic[1].update({2:3})

In [29]: dic
Out[29]: {1: {1: 2, 2: 3}}

dict[1][2] = 3

它访问索引为1的第一个字典,然后将该字典的2键分配给3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM