Pythonic way to check if two dictionaries have the identical set of keys?

前端 未结 6 2064
日久生厌
日久生厌 2020-12-14 15:50

For example, let\'s say I have to dictionaries:

d_1 = {\'peter\': 1, \'adam\': 2, \'david\': 3}

and

d_2 = {\'peter\': 14, \         


        
6条回答
  •  眼角桃花
    2020-12-14 16:19

    A quick option (not sure if its the most optimal)

    len(set(d_1.keys()).difference(d_2.keys())) == 0
    

提交回复
热议问题