Skip to content

Instantly share code, notes, and snippets.

@accolver
Created December 6, 2017 01:07
Show Gist options
  • Save accolver/54d164176ef5f36f31d8a52deb47c70a to your computer and use it in GitHub Desktop.
Save accolver/54d164176ef5f36f31d8a52deb47c70a to your computer and use it in GitHub Desktop.
Randomly match items of list together. I'm using this to match siblings together for Christmas gift giving.
"""Randomly match list items together."""
import sys
import random
if len(sys.argv) < 2:
raise('Must pass in list of items (Ex: "John,Michael,Alan,Bryanne"')
try:
seed = sys.argv[2]
except IndexError:
seed = None
random.seed(seed)
items = sys.argv[1].split(',')
random.shuffle(items)
total = len(items)
i = 0
while i < total:
if total - i == 1:
print('%s' % items[i])
else:
print('%s -- %s' % (items[i], items[i + 1]))
i += 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment