Calculate difference in keys contained in two Python dictionaries

后端 未结 21 1392
眼角桃花
眼角桃花 2020-11-27 09:33

Suppose I have two Python dictionaries - dictA and dictB. I need to find out if there are any keys which are present in dictB but not

21条回答
  •  抹茶落季
    2020-11-27 10:06

    Based on ghostdog74's answer,

    dicta = {"a":1,"d":2}
    dictb = {"a":5,"d":2}
    
    for value in dicta.values():
        if not value in dictb.values():
            print value
    

    will print differ value of dicta

提交回复
热议问题