Skip to content

Instantly share code, notes, and snippets.

@Da-Juan
Last active December 5, 2018 12:30
Show Gist options
  • Save Da-Juan/6f8b26c165d2c2c381b8b8384d04180c to your computer and use it in GitHub Desktop.
Save Da-Juan/6f8b26c165d2c2c381b8b8384d04180c to your computer and use it in GitHub Desktop.
Radomize secret santa pairings
#!/usr/bin/python3
import random
people = [
"Foo",
"Bar",
"Baz",
"Qux",
"Quux",
"Corge",
"Grault",
"Garply",
"Waldo",
"Fred",
"Plugh",
"Xyzzy",
"Thud",
]
def valid(a, b):
for i, j in zip(a, b):
if i == j:
return False
return True
givers = list(people)
recipients = list(people)
while not valid(givers, recipients):
random.shuffle(givers)
random.shuffle(recipients)
# sort pairings alphabetically with case insensitive
pairings = sorted(
list(zip(givers, recipients)),
key=lambda tup: tup[0].casefold()
)
for p in pairings:
print('%s -> %s' % (p[0], p[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment