Last active
August 29, 2015 14:01
-
-
Save kousu/4786d0708a693a11f117 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def humanized_diff(L, delta): | |
""" | |
Convert the given (sorted!!) tabular diff to a string, | |
marked up with +s and -s, similar to regular diff(1)'s "-u" mode. | |
""" | |
D, A = delta | |
U, D = drop(L, D), [L[i] for i in D] | |
def prefix(v, S): | |
return [(v,s) for s in S] | |
A = prefix("+", A) | |
D = prefix("-", D) | |
U = prefix(" ", U) | |
R = merge(A,D,U, key=lambda v: v[1]) | |
R = ["%s%s" % (r[0], r[1]) for r in R] | |
return str.join("\n", R) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment