Combining two dictionaries into one with the same keys?

前端 未结 7 1756
眼角桃花
眼角桃花 2020-12-06 03:35

I\'ve looked through a few of the questions here and none of them seem to be exactly my problem. Say I have 2 dictionaries, and they are dict1

{\'A\': 25 ,          


        
相关标签:
7条回答
  • 2020-12-06 04:34

    As you know that your two dictionaries will always have the same keys, you could use:

    finaldict = {key:(dict1[key], dict2[key]) for key in dict1}
    

    to combine them, where each value would be a tuple of the values from the source dictionaries.

    0 讨论(0)
提交回复
热议问题