Skip to content

Instantly share code, notes, and snippets.

@gtr
Created December 18, 2020 21:29
Show Gist options
  • Save gtr/8b0c6057c7198029b5740df3ef80e2a7 to your computer and use it in GitHub Desktop.
Save gtr/8b0c6057c7198029b5740df3ef80e2a7 to your computer and use it in GitHub Desktop.
a quick script to generate random pairings for #secret #santa gifts 🎄 🎅
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