Comparison of dictionaries using cmp() in Python
cmp() is a function that we can use to compare two dictionaries.
The dictionary comparison is done in the following order using cmp():
1) size
2) key
3) value
First, the size of the elements is checked, then the keys are compared and then values are compared.
Syntax:
|
1 |
cmp(dictionary_one, dictionary_two) |
Based on the size, key and then value comparison,
a) If the dictionary_one is greater than dictionary_two, then 1 is returned.
b) If the dictionary_one is less than dictionary_two, then -1 is returned.
c) If the dictionary_one is equal to dictionary_two, then 0 is returned.