Created
November 18, 2021 02:57
-
-
Save ezr/0c8b9f4562ea1796c798aa95d21c4578 to your computer and use it in GitHub Desktop.
takes lists and merges them into columns
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
#!/usr/bin/env python3 | |
import argparse | |
from sys import argv, stderr | |
parser = argparse.ArgumentParser(description='zip together lists') | |
parser.add_argument("-s", "--separator", default=" ", help='character to separate items', required=False) | |
parser.add_argument("lists", nargs="+") | |
args = parser.parse_args() | |
lists = list(map(lambda x: x.strip().split("\n"), args.lists)) | |
if len(dict.fromkeys(map(len, lists))) != 1: | |
print("[!] warning - lists were not all the same length", file=stderr) | |
zipped = zip(*lists) | |
for t in zipped: | |
for i, item in enumerate(t): | |
print(item, end=args.separator) if i+1 != len(t) else print(item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Examples: