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

前端 未结 6 2076
日久生厌
日久生厌 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:01

    >>> not set(d_1).symmetric_difference(d_2)
    False
    >>> not set(d_1).symmetric_difference(dict.fromkeys(d_1))
    True
    

提交回复
热议问题