Created
April 15, 2024 15:54
-
-
Save hepplerj/3575c485bb2dde941033e31760ae2e07 to your computer and use it in GitHub Desktop.
Pairing up names
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/python3 | |
import random | |
def pair_names(filename, output_filename): | |
with open(filename, 'r') as f: | |
names = [line.strip() for line in f] | |
random.shuffle(names) | |
pairs = [names[n:n+2] for n in range(0, len(names), 2)] | |
if len(names) % 2 != 0: | |
pairs[-2].append(pairs[-1][0]) | |
pairs = pairs[:-1] | |
with open(output_filename, 'w') as f: | |
for pair in pairs: | |
f.write(' & '.join(pair) + '\n') | |
pair_names('names.txt', 'pairings.txt') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment