How to use == operator to Compare Two Dictionaries In Python
Here we are using the equality comparison operator in Python to compare two dictionaries whether both have the same key value pairs or not.
Python
dict1 = { 'Name' : 'asif' , 'Age' : 5 } dict2 = { 'Name' : 'lalita' , 'Age' : 78 } if dict1 = = dict2: print "dict1 is equal to dict2" else : print "dict1 is not equal to dict2" |
Output:
dict1 is not equal to dict2
How to Compare Two Dictionaries in Python?
In this article, we will discuss how to compare two dictionaries in Python. As we all know what is a dictionary, but sometimes we may need to compare two dictionaries. Let’s see different methods to do the same.