在字典中添加字典 [英] Adding a dictionary inside a dictionary
本文介绍了在字典中添加字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一本类似的字典:
store = {}
我在另一本字典中有很多数据,如下所示:
And I have a bunch of data in another dictionary that looks like this:
items = {"hardware_items":23, "fruit_items":5, "fish_items": 23}
如何放置商店字典中的项字典,这样我可以实现以下结果?
How can I put the items dictionary inside the store dict so I can achieve the following result?
store = {"hardware_items":23, "fruit_items":5, "fish_items": 23}
谢谢
推荐答案
使用 update
方法:
store.update(items)
这会将个项目
中的所有内容添加到 store
;但是请注意,如果 store
已经存在具有这些名称的键,则它们将被覆盖。
This will add everything in items
to store
; beware though that if store
already has existing keys with those names they will be overwritten.
这篇关于在字典中添加字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文