In this post, we look at how to compare two lists of dictionaries in Python and also print out the differences between the two lists.
The comparison method compares keys and values in the dictionaries.
Also, the ordering of elements does not matter when comparing two lists of dictionaries in Python.
Compare list of dictionaries in Python
In the above code,
list_2 are equal. That is, each dictionary contains the same items (keys and values) in both lists. The order of elements in each dictionary is irrelevant.
Compare list of dictionaries - print differences
We can also print which dictionary items are different in the lists: