Skip to content

Instantly share code, notes, and snippets.

@rectangletangle
Created June 20, 2015 19:11
Show Gist options
  • Save rectangletangle/bba2b13ed82ef4287d92 to your computer and use it in GitHub Desktop.
Save rectangletangle/bba2b13ed82ef4287d92 to your computer and use it in GitHub Desktop.
Text Blocking
def blockify(lines):
assert len({len(line) for line in lines}) in {0, 1}
return [''.join(section)
for section in zip(*lines)]
if __name__ == '__main__':
assert blockify([]) == []
assert blockify(['AAA', 'BBB', 'CCC']) == ['ABC', 'ABC', 'ABC']
assert blockify(['AAAAAAAAAAAAA']) == ['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A']
assert blockify(['A', 'A', 'A', 'A', 'A']) == ['AAAAA']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment