When my friends and I were picking teams for a golf event, we realized we needed a quick and easy way to randomly, and thereby fairly, pick teams.
Sure we could have used the old draw from a hat style selection, but something about that doesn’t sit right wit me. So instead, I wrote a quick and dirty Python program to generate random teams of two for us.
import random
participants = [
'Hogan',
'Colten',
'Colton',
'Tyler',
'Kyle',
'Benton',
'Franko',
'Gray'
]
random_numbers = random.sample(range(len(participants)), len(participants))
tup = list(zip(participants, random_numbers))
def pair_players(tup):
tup.sort(key = lambda x: x[1])
return tup
pairings = pair_players(tup)
for i in range(0,len(pairings), 2):
print(f'{pairings[i][0]} && {pairings[i+1][0]}')
If you like this content, subscribe to our email list in order to get notified about new post.