Last active
September 7, 2020 20:31
-
-
Save Laski/6aa7d8d60e64a55ff50fab31df69d871 to your computer and use it in GitHub Desktop.
Código base de ejemplo para mi artículo sobre anotaciones de tipos en Python 3
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
from collections import defaultdict | |
class KillEvent: | |
def __init__(self, killer, victim): | |
self.killer = killer | |
self.victim = victim | |
class Match: | |
def __init__(self, players): | |
self.players = players | |
self.events = [] | |
def new_kill(self, killer, victim): | |
kill = KillEvent(killer, victim) | |
self.events.append(kill) | |
def score_table(self): | |
score = defaultdict(int) # esto inicializa todos los values en 0 | |
for kill in self.events: | |
score[kill.killer] += 1 | |
score[kill.victim] -= 1 | |
return score | |
def score_for(self, player): | |
score_table = self.score_table() | |
return score_table[player] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment