Created
December 6, 2017 01:07
-
-
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.
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
"""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