【发布时间】:2013-02-15 06:32:26
【问题描述】:
假设我有这个:
config = {
"a": {
"hello": 1,
"goodbye": 2,
}
}
我想像这样将["a"]["hello"] 更新为 10:
update = {
"a": {
"hello": 10
}
}
config.update(update)
此时配置为:
config = {
"a": {
"hello": 10
}
}
如何在不覆盖其他值/子字典的情况下用另一个字典更新一个字典?
【问题讨论】:
-
为什么不只是
config['a']['hello'] = 10?
标签: python dictionary