• Post author:
  • Post category:Python
  • Reading time:1 mins read

Here is an example of a Python program to compare two dictionaries keys and values.


Compare Two Dictionaries Keys and Values in Python

a = {
   'Apple' : 10,
   'Orange' : 20,
   'Mango' : 30

b = {
   'Grapes' : 100,
   'Apple' : 110,
   'Orange' : 20

print('Common keys:', a.keys() & b.keys())
print('Keys in a not in b:', a.keys() - b.keys())
print('(key,value) pairs in common:', a.items() & b.items())


Common keys: {'Orange', 'Apple'}
Keys in a not in b: {'Mango'}
(key,value) pairs in common: {('Orange', 20)}

Process finished with exit code 0

See also:

Related:  Setting Python 2.7 in PyCharm

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.