Kodewick
Start learning →
Basic←→0 / 100

Who won the vote

#062BasicDictsLoops5 min

The class voted for a class rep and the votes are in a dict of name to count. Write winner(votes) to return the name with the most votes. On a tie, return the one that comes first in the dict. There is always at least one name.

Examples
winner({"Amy": 5, "Ben": 8, "Cat": 3})→'Ben'
winner({"Leo": 4, "Mia": 4})→'Leo'
main.py
def winner(votes):
    best_name = ""
    best_count = -1
    for name, count in votes.items():
        # your code here: more than best_count? remember this one
        pass
    return best_name
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.