Skip to content

Instantly share code, notes, and snippets.

@kousu
Last active August 29, 2015 14:01
Show Gist options
  • Save kousu/4786d0708a693a11f117 to your computer and use it in GitHub Desktop.
Save kousu/4786d0708a693a11f117 to your computer and use it in GitHub Desktop.
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