-
Notifications
You must be signed in to change notification settings - Fork 8
/
tournamentWinner.py
45 lines (37 loc) · 1.33 KB
/
tournamentWinner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# def tournamentWinner(competitions, results):
# teamNames = getAllAvailableTeamName(competitions)
# for idx in range(len(competitions)):
# result = 1 if results[idx] == 0 else 0
# teamNames[competitions[idx][result]] += 3
# print(teamNames)
# ret = ""
# score = 0
# for team, point in teamNames.items():
# if point > score:
# ret = team
# score = point
# return ret
# def getAllAvailableTeamName(competitions):
# names = {}
# for i in range(len(competitions)):
# if competitions[i][0] not in names:
# names[competitions[i][0]] = 0
# if competitions[i][1] not in names:
# names[competitions[i][1]] = 0
# return names
HOME_TEAM_WON = 1
def tournamentWinner(competitions, results):
currentBestTeam = ""
scores = {currentBestTeam: 0}
for idx, competition in enumerate(competitions):
result = results[idx]
homeTeam, awayTeam = competition
winningTeam = homeTeam if result == HOME_TEAM_WON else awayTeam
updateScores(winningTeam, 3, scores)
if scores[winningTeam] > scores[currentBestTeam]:
currentBestTeam = winningTeam
return currentBestTeam
def updateScores(team, points, scores):
if team not in scores:
scores[team] = 0
scores[team] += points