Python program How to Compare two dictionary.
In this example shows, we will give three dictionaries a,b and c and compare them to the dictionaries, if both dictionaries are equal it is true. The condition is (a == b), the equal-to operator.
Example.py
a = {'Roll_No': 101, 'name': 'Ramkumar', 'class': 21, 'section':'A'} b = {'Roll_No': 101, 'name': 'Ramkumar', 'class': 21, 'section':'A'} c = {'Roll_No': 102, 'name': 'Samkumar', 'class': 23, 'section':'B'} if a == b: print("a is equal to b") else: print("a is not equal to b") if b == c: print("b is equal to c") else: print("b is not equal to c")
Output
a is equal to b b is not equal to c