Created
December 18, 2020 21:29
-
-
Save gtr/8b0c6057c7198029b5740df3ef80e2a7 to your computer and use it in GitHub Desktop.
a quick script to generate random pairings for #secret #santa gifts 🎄 🎅
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
import random | |
def getNames(): | |
names = [] | |
f = open('names.txt', 'r') | |
for line in f: | |
names.append(line.strip('\n')) | |
return names | |
def makePairings(names): | |
pairs = [] | |
size = len(names) | |
shuffled = random.sample(names, size) | |
for i in range(size - 1): | |
pairs.append((shuffled[i], shuffled[i + 1])) | |
pairs.append((shuffled[size - 1], shuffled[0])) | |
return pairs | |
def printPairings(pairs): | |
for i in range(len(pairs)): | |
print(pairs[i][0], "->", pairs[i][1]) | |
def main(): | |
names = getNames() | |
pairs = makePairings(names) | |
printPairings(pairs) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment