How to check if at least one key in dictionary exists as a value in another dictionary in Python?

  • A+

I am creating a function that accepts a dictionary1 and checks if any of the keys exists as a value dictionary2.

I have tried using the dictionary2.isdisjoint(dictionary1) but this is effective for only checking keys-keys.

How can I check key to value in Python?


Not sure if this is really a big enough task to put into a separate function, but anyway, here's an example using the any() keyword:

if any(k in d2.values() for k in d1.keys()):     # do stuff 


:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: