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?
I'd also like to note that while @heyitsmarcus 's answer works it's a bit inefficient since it iterates through the dictionary twice. A more efficient version would be like this:
def findImposters(votes):
ejected = []
max = 0
for color, voteCount in votes.items():
if voteCount == max:
ejected.append(color)
elif voteCount > max:
ejected = [color]
max = voteCount
return 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!
@Smart0ne No problem!
I'd also like to note that while @heyitsmarcus 's answer works it's a bit inefficient since it iterates through the dictionary twice. A more efficient version would be like this: