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

Image comparison algorithm

A similar question was asked a year ago and has numerous responses, including one regarding pixelizing the images, which I was going to suggest as at least a pre-qualification step (as it would exclude very non-similar images quite quickly). There are also links there to still-earlier questions which have even more references and good answers. … Read more

Compare 2 JSON objects [duplicate]

Simply parsing the JSON and comparing the two objects is not enough because it wouldn’t be the exact same object references (but might be the same values). You need to do a deep equals. From http://threebit.net/mail-archive/rails-spinoffs/msg06156.html – which seems the use jQuery. Object.extend(Object, { deepEquals: function(o1, o2) { var k1 = Object.keys(o1).sort(); var k2 = … Read more

Comparing text files with Junit

Here’s one simple approach for checking if the files are exactly the same: assertEquals(“The files differ!”, FileUtils.readFileToString(file1, “utf-8”), FileUtils.readFileToString(file2, “utf-8”)); Where file1 and file2 are File instances, and FileUtils is from Apache Commons IO. Not much own code for you to maintain, which is always a plus. 🙂 And very easy if you already happen … Read more

Compare 2 directories in windows [closed]

The following PowerShell code compares the file listings of two folders. It will detect renamed or newly created files and folders, but it will not detect modified data or different timestamps: $dir1 = Get-ChildItem -Recurse -path C:\dir1 $dir2 = Get-ChildItem -Recurse -path C:\dir2 Compare-Object -ReferenceObject $dir1 -DifferenceObject $dir2 Source: MS Devblog – Dr. Scripto 3rd … Read more

Java. Ignore accents when comparing strings

I think you should be using the Collator class. It allows you to set a strength and locale and it will compare characters appropriately. From the Java 1.6 API: You can set a Collator’s strength property to determine the level of difference considered significant in comparisons. Four strengths are provided: PRIMARY, SECONDARY, TERTIARY, and IDENTICAL. … Read more

How to compare Enums in Python?

You should always implement the rich comparison operaters if you want to use them with an Enum. Using the functools.total_ordering class decorator, you only need to implement an __eq__ method along with a single ordering, e.g. __lt__. Since enum.Enum already implements __eq__ this becomes even easier: >>> import enum >>> from functools import total_ordering >>> … Read more