python dictionary match key values in two dictionaries

前端 未结 4 613
旧巷少年郎
旧巷少年郎 2020-12-16 04:08

In the below shown dictionaries i want to check whether the key in aa matches the key in bb and also the value corresponding to it matches in bb or not.Is there a better way

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 04:53

    If you want to iterate over all matching key/value pairs, you can use

    for key, value in aa.viewitems() & bb.viewitems():
        ...
    

    (Python 2.7)

提交回复
热议问题