def compress(a, b):
from difflib import ndiff<EOL>left = a.splitlines(<NUM_LIT:1>) if isinstance(a, string_types) else a<EOL>right = b.splitlines(<NUM_LIT:1>) if isinstance(b, string_types) else b<EOL>ldiff = list(ndiff(left, right))<EOL>result = {}<EOL>latest = None   <EOL>combo = None<EOL>icombo = <NUM_LIT:0><EOL>iorig = <NUM_LIT:0><EOL>for i, line in enumerate(ldiff):<EOL><INDENT>cs = [l[<NUM_LIT:0>] for l in ldiff[i:min((i+<NUM_LIT:4>, len(ldiff)))]]<EOL>if cs[<NUM_LIT:0>] != '<STR_LIT:U+0020>':<EOL><INDENT>if latest is None:<EOL><INDENT>latest = iorig<EOL>result[latest] = []<EOL><DEDENT>if combo is None:<EOL><INDENT>if cs[<NUM_LIT:0>] == '<STR_LIT:->':<EOL><INDENT>if (len(cs) >=<NUM_LIT:3> and cs[<NUM_LIT:1>] == '<STR_LIT:+>' and cs[<NUM_LIT:2>] == '<STR_LIT:?>'):<EOL><INDENT>combo = <NUM_LIT:3><EOL><DEDENT>elif (len(cs) >= <NUM_LIT:4> and cs[<NUM_LIT:1>] == '<STR_LIT:?>' and cs[<NUM_LIT:2>] == '<STR_LIT:+>'<EOL>and cs[<NUM_LIT:3>] == '<STR_LIT:?>'):<EOL><INDENT>combo = <NUM_LIT:4><EOL><DEDENT>else:<EOL><INDENT>combo = <NUM_LIT:1><EOL><DEDENT><DEDENT>elif cs[<NUM_LIT:0>] == '<STR_LIT:+>':<EOL><INDENT>combo = <NUM_LIT:1><EOL><DEDENT><DEDENT>if icombo < combo:<EOL><INDENT>result[latest].append(line)<EOL>icombo += <NUM_LIT:1><EOL><DEDENT>if icombo == combo:<EOL><INDENT>if combo > <NUM_LIT:1>:<EOL><INDENT>latest = None<EOL><DEDENT>combo = None<EOL>icombo = <NUM_LIT:0><EOL>if cs[<NUM_LIT:0>] != '<STR_LIT:+>':<EOL><INDENT>iorig += <NUM_LIT:1><EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>latest = None<EOL>iorig += <NUM_LIT:1><EOL><DEDENT><DEDENT>return result<EOL>
Performs the *compressed* diff of `a` and `b` such that the original
    contents of the :func:`difflib.ndiff` call can be reconstructed using
    :func:`~acorn.logging.diff.restore`.

    Args:
        a (str or list): *original* string or list of strings to diff.
        b (str or list): *edited* string or list of strings to diff.