Skip to content

Instantly share code, notes, and snippets.

@anroopak
Created December 14, 2018 08:05
Show Gist options
  • Save anroopak/10b4a494c682eaf79d491b1ffd913269 to your computer and use it in GitHub Desktop.
Save anroopak/10b4a494c682eaf79d491b1ffd913269 to your computer and use it in GitHub Desktop.
Compare 2 lists of dicts without order
# 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