python - 如何在 python 2.7 中合并两个以上的字典
问题描述
尝试在 python 2.7 中合并两个或多个字典,但是
** kwargs在 python 2.7 中不受支持,它会给出错误,如 Python 2.7 版不支持 dicts 中的星号表达式。
有没有办法在 python 2.7 中做到这一点?
# Create first dictionary
dict1 = { 'Ritika': 5, 'Sam': 7, 'John' : 10 }
# Create second dictionary
dict2 = {'Aadi': 8,'Sam': 20,'Mark' : 11 }
# Create second dictionary
dict3 = {'x': 8,'y': 20,'z' : 11 }
dict4 = {**dict1 , **dict2, **dict3}
print dict4
预期产出-
{'Ritika': 5, 'Sam': 20, 'John': 10, 'Aadi': 8, 'Mark': 11, 'x': 8, 'y': 20, 'z': 11}
解决方案
推荐阅读
- android - 了解 Android Vitals 在 Play 商店控制台中提供的 ANR 日志
- vba - 将 .docx 中的字符串替换为 Excel 中的值,保留 Excel 大写
- c# - 创建反对角单位矩阵
- sql-server - 无法从 MYSQL 工作台 6.3 CE 连接到 MS SQL 服务器
- android - Xamarin Android Firebase 用户:如何获取创建日期
- python - jsons 中集合的最佳实践:array vs dict/map
- azure - 将 json 数组发布到 Azure 上的 Spring 控制器时出现 400 错误请求
- java - 在数据库中存储一个大字符串?
- microsoft-graph-api - 如何使用 Graph API 从共享点获取列表项
- java - 相同的 log4j2 xml 但输出不同