It's a dictionary named "votes". Now I want a function that can return the key names of the values that have the maximum value. If this is unclear, the function should return
ejected = ["red","cyan"]
since "red" and "cyan" have the biggest values in the dictionary. Can someone help me implement this?
As long as everything works that is great, but I originally looped through twice before I refactored.
votes = {"red":2,"yellow":1,"green":0,"cyan":2,"blue":1,"magenta":0}
def findImpostors(votes):
# this will created the ejected list
ejected = []
# get the maximum value in the list of values of the dictionary
maximum = max(votes.values())
# this will take care of any repeating numbers (i.e. the two with 2 votes)
for color, voteCount in votes.items():
# if their vote count matches the max
if voteCount == maximum:
# they're getting ejected, fool!
ejected.append(color)
return ejected
ejected = findImpostors(votes)
print(ejected)
Among Us Voting System: HALP AGAIN
Hi repl.it
Let's say I have the following code:
It's a dictionary named "votes". Now I want a function that can return the key names of the values that have the maximum value. If this is unclear, the function should return
since "red" and "cyan" have the biggest values in the dictionary. Can someone help me implement this?
Thanks in advance!
As long as everything works that is great, but I originally looped through twice before I refactored.