PyMOTW: difflib

The difflib module contains several classes for comparing sequences, especially of lines of text from files, and manipulating the results. The SequenceMatcher class compares any 2 sequences of values, as long as the values are hash-able. It uses a recursive algorithm to identify the longest contiguous matching blocks from the sequences, eliminating “junk” values. The Differ class works on sequences of text lines and produces human-readable deltas, including differences within individual lines. The HtmlDiff class produces similar results formatted as an HTML table.

Read more at difflib