Created
August 30, 2012 11:20
-
-
Save informationsea/3526570 to your computer and use it in GitHub Desktop.
Transpose Text Matrix
This file contains hidden or 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
#!/usr/bin/env python | |
import argparse | |
import sys | |
import itertools | |
def _main(): | |
parser = argparse.ArgumentParser(description='Transpose text array') | |
parser.add_argument('input', default=sys.stdin, nargs='?', type=argparse.FileType('r')) | |
parser.add_argument('output', default=sys.stdout, nargs='?', type=argparse.FileType('r')) | |
options = parser.parse_args() | |
lines = [x.split() for x in options.input.readlines()] | |
for i in itertools.izip_longest(*lines): | |
print >>options.output, '\t'.join(i) | |
if __name__ == '__main__': | |
_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment