Skip to content

Instantly share code, notes, and snippets.

@timrprobocom
Created August 19, 2023 00:27

Revisions

  1. timrprobocom created this gist Aug 19, 2023.
    25 changes: 25 additions & 0 deletions untangle.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    lines = """\
    ABCDE12345_001,FGHIJ6789_002,ABCDE12345_001
    KLMNO5432_003,KLMNO5432_003,FGHIJ6789_002
    PQRST24680_123,UVWXY13579_555,UVWXY13579_555
    ZABCD876530_009,ZABCD876530_009,AABBCCDDEE_987
    AABBCCDDEE_987,AABBCCDDEE_987,LMNOP98765_999
    LMNOP98765_999,ZYXWV54321_777,ZYXWV54321_777""".splitlines()

    record = []
    for row in lines:
    record += [(word,ordinal) for ordinal,word in enumerate(row.split(','))]

    record.sort()

    last = None
    build = None
    for word,posn in record:
    if word != last:
    if build:
    print(','.join(build))
    build = ['','','']
    last = word
    build[posn] = word

    print(','.join(build))