【发布时间】:2021-06-12 02:39:18
【问题描述】:
我使用 python 开发,并且我有多个字典,例如:
Dict1: {‘hi’:’340’, ‘hello’:’570’, ’me’:´800’}
Dict1: {‘hi’:’200’, ‘hello’:’100’, ’me’:´389’}
我想将它们一起添加到一个字典中:
Dict_new= { {‘hi’:’340’,‘hello’:’570’, ’me’:´800’}, {‘hi’:’200’, ‘hello’:’100’, ’me’:´389’}}
最后我希望得到这个输出:
{‘elements’:{{‘hi’:’340’,‘hello’:’570’,
’me’:´800’},
{‘hi’:’200’, ‘hello’:’100’,
’me’:´389’}}}
那么最好的方法是什么?
【问题讨论】:
-
也许让它成为一个字典列表而不是字典的字典。
-
你想
mergedicts吗?您不能将字典添加到另一个字典,因为它们不是hashable type。
标签: python python-3.x dictionary data-science