Skip to content

Instantly share code, notes, and snippets.

@gabbyprecious
Created August 28, 2022 00:17
Show Gist options
  • Save gabbyprecious/a172a33bbc643056723526ac511a86dd to your computer and use it in GitHub Desktop.
Save gabbyprecious/a172a33bbc643056723526ac511a86dd to your computer and use it in GitHub Desktop.
Tournament Winner DS/AL
# Online Python - IDE, Editor, Compiler, Interpreter
Competitors = [
["HTML", "C#"],
["C#", "Python"],
["Python", "HTML"]
]
results = [0, 0, 1]
def get_winner(comp, res):
dictComp = {}
team_list = []
for lister in comp:
for item in lister:
if item not in team_list:
team_list.append(item)
for team in team_list:
dictComp[team] = 0
for index,item in enumerate(comp):
winning_team = None
losing_team = None
if res[index] == 0:
winning_team = item[1]
losing_team = item[0]
else:
winning_team = item[0]
losing_team = item[1]
print(f"{winning_team} beats {losing_team}")
dictComp[winning_team] = dictComp.get(winning_team)+ 3
fin_winner = max(dictComp, key=dictComp.get)
for key, value in dictComp.items():
print(f"{key} has {value} points")
print(f"{fin_winner} won")
get_winner(Competitors, results)
@Youngestdev
Copy link

# Online Python - IDE, Editor, Compiler, Interpreter

Competitors = [
    ["HTML", "C#"], 
    ["C#", "Python"], 
    ["Python", "HTML"]
]
results = [0, 0, 1]

def get_winner(comp, res):
    dictComp = {}
    for lister in comp:
        for item in lister:
            dictComp[item] = 0

    for index,item in enumerate(comp):
        winning_team = None
        losing_team = None
        if res[index] == 0:
            winning_team = item[1]
            losing_team = item[0]
        else:
            winning_team = item[0]
            losing_team = item[1]
        print(f"{winning_team} beats {losing_team}")
        dictComp[winning_team] =  dictComp.get(winning_team)+ 3
        
    fin_winner = max(dictComp, key=dictComp.get)
    for key, value in dictComp.items():
        print(f"{key} has {value} points")
    print(f"{fin_winner} won")

get_winner(Competitors, results)

@gabbyprecious
Copy link
Author

Yeahhh just saw that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment