我刚开始学习Python并查看了其他合并字典的答案,但仍有些困惑。我想要通过特定键中的公共值将两个字典合并在一起,以输出具有该公共键以及来自两个字典的其他键的新字典。
这是示例数据:
add_sal = {'career_medicine': None, 'career_law': None, 'median_salary': None, 'mean_salary': 75000.0, 'career_business': 'operations / logistics', 'number': None}
add_perc = {'percent': 0.07, 'career_business': 'operations / logistics'}
我想根据'career_business':'operations / logistics'这个键值对进行合并,并输出一个类似于以下格式的字典:add_all = {'career_medicine': None, 'career_law': None, 'median_salary': None, 'mean_salary': 75000.0, 'career_business': 'operations / logistics', 'number': None, 'percent': 0.07}
另一个问题是我不知道名称是否匹配,我正在循环遍历add_sal列表和add_perc列表。
欢迎提供任何建议!提前感谢您!