Secret Santa script written in Python

Created by
Monday, November 28, 2016

 

import random
import itertools

list_of_participants = [
    'Pam',
    'Gemma',
    'Peter',
    'John',
]

def valid(x, y):
    for i, j in itertools.zip_longest(x, y):
        if i == j: return False
    return True

x = list(list_of_participants)
y = list(list_of_participants)

while not valid(x, y):
    random.shuffle(x)
    random.shuffle(y)

for i, j in itertools.zip_longest(x, y):
    print('%s == %s' % (i, j))
Tags:
python
0
Rating
1 2 3 4 5

Save

Saved

Report

Reported
Reasons
Cancel
0 comments