首页 > 解决方案 > 在字典中添加字典

问题描述

我有一本看起来像这样的字典:

store = {}

我在另一个字典中有一堆数据,如下所示:

items = {"hardware_items":23, "fruit_items":5, "fish_items": 23}

如何将 items 字典放入 store dict 中,以便获得以下结果?

store = {"hardware_items":23, "fruit_items":5, "fish_items": 23}

谢谢

标签: python-3.xdictionary

解决方案


使用update方法:

store.update(items)

这会将所有内容添加itemsstore; 请注意,如果store已经有具有这些名称的现有密钥,它们将被覆盖。


推荐阅读