Skip to content

Instantly share code, notes, and snippets.

@crissilvaeng
Created March 17, 2021 23:27
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 crissilvaeng/a25c7a80a6065936e76d750292078a2a to your computer and use it in GitHub Desktop.
Save crissilvaeng/a25c7a80a6065936e76d750292078a2a to your computer and use it in GitHub Desktop.
Python League
from itertools import combinations
from random import choice
players = ['Cristina', 'Rodrigo', 'Moises', 'Wagner', 'Arthur']
league = list(combinations(players, 2))
print(league)
def victory_host(ranking, host, away):
ranking[host] = ranking.get(host, 0) + 3
ranking[away] = ranking.get(away, 0) - 3
def victory_away(ranking, host, away):
ranking[host] = ranking.get(host, 0) - 3
ranking[away] = ranking.get(away, 0) + 3
def draw(ranking, host, away):
ranking[host] = ranking.get(host, 0) + 1
ranking[away] = ranking.get(away, 0) + 1
handlers = { 'host.win': victory_host, 'away.win': victory_away, 'draw': draw }
ranking = {}
for game in league:
result = choice(list(handlers.keys()))
handler = handlers.get(result)
handler(ranking, game[0], game[1])
print(f'[{result.upper()}]\t{game[0]} x {game[1]}')
print(ranking)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment