Calculate difference in keys contained in two Python dictionaries

后端 未结 21 1452
眼角桃花
眼角桃花 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 09:40

    not sure whether its "fast" or not, but normally, one can do this

    dicta = {"a":1,"b":2,"c":3,"d":4}
    dictb = {"a":1,"d":2}
    for key in dicta.keys():
        if not key in dictb:
            print key
    

提交回复
热议问题