Created
July 22, 2020 19:26
-
-
Save jpignata/e3e0e0f03b7f720d49e7a9feaa2ca8f4 to your computer and use it in GitHub Desktop.
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 | |
from random import shuffle | |
from sys import argv | |
from typing import Iterator, List, Tuple | |
def pairs(names: List[str], default: str) -> Iterator[Tuple[str, str]]: | |
names = names.copy() | |
if len(names) % 2 != 0: | |
names.append(default) | |
shuffle(names) | |
return ((names.pop(), names.pop()) for _ in range(len(names) // 2)) | |
if __name__ == '__main__': | |
default = 'jp' | |
if len(argv) < 2: | |
print('Usage: ./buds.py [NAME] [NAME] ...') | |
names = argv[1:] | |
width = len(max(names, key=len)) | |
for name1, name2 in pairs(names, default): | |
print(f'{name1:<{width}} {name2:<{width}}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment