Created
June 20, 2015 19:11
-
-
Save rectangletangle/bba2b13ed82ef4287d92 to your computer and use it in GitHub Desktop.
Text Blocking
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 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