Skip to content

Instantly share code, notes, and snippets.

@Lokno
Last active November 21, 2021 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lokno/42755d897913fe5a94442ed34974601e to your computer and use it in GitHub Desktop.
Save Lokno/42755d897913fe5a94442ed34974601e to your computer and use it in GitHub Desktop.
Short python 3 script for randomly generating giftees for a gift exchange between 2 or more people.
from random import shuffle
from sys import argv
from pathlib import Path
names = []
if len(argv) == 2:
file_path = Path(argv[1])
if not file_path.exists():
print(f'File not found: {argv[1]:s}')
else:
with open(argv[1],'r') as f:
names = [n.rstrip().upper() for n in f.readlines() if n.rstrip() != '']
n = len(names)
if n > 2:
shuffle(names)
for i in range(n):
name1 = names[i]
name2 = names[(i+1) % n]
print (f'{name1:s}\'s secret giftee is {name2:s}')
else:
print('List must contain more than 1 name')
else:
print(f' usage: {argv[0]:s} <input.txt>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment