Comparing 2 lists consisting of dictionaries with unique keys in python

Assuming that the dicts line up like in your example input, you can use the zip() function to get a list of associated pairs of dicts, then you can use any() to check if there is a difference: >>> 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’, … Read more

Sort an array in the same order of another array

Use indexOf() to get the position of each element in the reference array, and use that in your comparison function. var reference_array = [“ryan”, “corbin”, “dan”, “steven”, “bob”]; var array = [“bob”, “dan”, “steven”, “corbin”]; array.sort(function(a, b) { return reference_array.indexOf(a) – reference_array.indexOf(b); }); console.log(array); // [“corbin”, “dan”, “steven”, “bob”] Searching the reference array every time … Read more