Created
December 14, 2018 08:05
-
-
Save anroopak/10b4a494c682eaf79d491b1ffd913269 to your computer and use it in GitHub Desktop.
Compare 2 lists of dicts without order
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/12813633/how-to-assert-two-list-contain-the-same-elements-in-python/31832447 | |
list_1 = [{'unique_id':'001', 'key1':'AAA', 'key2':'BBB', 'key3':'EEE'}, | |
{'unique_id':'002', 'key1':'AAA', 'key2':'CCC', 'key3':'FFF'}] | |
list_2 = [{'unique_id':'001', 'key1':'AAA', 'key2':'DDD', 'key3':'EEE'}, | |
{'unique_id':'002', 'key1':'AAA', 'key2':'CCC', 'key3':'FFF'}] | |
def compare_list_of_dicts(list_1, list_2): | |
pairs = zip(list_1, list_2) | |
return any(x != y for x, y in pairs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment