Question is as follows : In each competition there are two teams that compete. There will be one winner and one loser out of all of these competitions and there are no ties. Each team will compete against all other teams exactly once. A team gets 3 points for each competition it wins and 0 points for each competition it loses. It's guaranteed that the tournament always has at least two teams and there will be only one tournament winner.
We are given two inputs, the competitions array and the results array. We need to write a function that returns the winner of the tournament, or more specifically, the name of the team that has the most number of points.we have two strings: the first one is the name of the home team and the second one is the name of the away team. The results array represents the winner of each of these competitions. Inside the results array, a 1 means that the home team won and a 0 means the away team won. The results array is the same length as the competitions array, and the indices in the results array correspond with the indices in the competitions array.
def tournamentWinner(competitions, results):
# Write your code here.
d = {}
for i in range(len(results)):
if results[i] == 0:
if competitions[i][1] not in d:
d[competitions[i][1]] = 3
else:
d[competitions[i][1]] += 3
elif results[i] == 1:
if competitions[i][0] not in d:
competitions[i][0] = 3
else:
d[competitions[i][0]] += 3
print(max(d,key=d.get))
tournamentWinner([
["HTML", "Java"],
["Java", "Python"],
["Python", "HTML"],
["C#", "Python"],
["Java", "C#"],
["C#", "HTML"]
],[0, 1, 1, 1, 0, 1])
The output should be C#, but I am getting Java as per my code. Can someone please guide me through this?