Parsing diff results with python
===

Python beginner here.

I'm working with diffs at the moment.  I'm generating them with the [google python library][1].

Here's a sample of what a diff result looks like:

    [(0, 'Ok.  I just '), (-1, 'need to write '), (0, 'out a random bunch of text\nand then keep going.  I'), (-1, ' just'), (0, " did an enter to see how that goes and all\nthe rest of it.  I know I need.  Here's a skipped line.\n\nThen there is more and "), (-1, 't'), (0, 'hen there was the thing.')]

It's a list of tuples.  The first element in each tuple is the operator (0 - no change, -1 = deletion, 1 = addition).  The second element is the data that is added or deleted from a slab of text.

I want to summarise these diff results so a reader can get the gist of the changes by reading a few lines without having to read the whole slab of text that might only have 30 characters or so changed in it.

My first step towards this is to rank the tuples by character length, and then display the top 3 biggest changes (in their original order, with a bit of unchanged text on either side).

How do you think I should rank the tuples by character length, grab the three longest, and then rearrange them so the order is like the original?

Ideally, the result would look something like this (using example above):

...just <strike>need to write</strike>out a...
...I <strike>just</strike> did an enter...


  [1]: http://code.google.com/p/google-diff-match-patch/