Implement most_frequent_value function
This commit is contained in:
parent
524581e2fc
commit
39b258ffec
@ -1,2 +1,17 @@
|
|||||||
def most_frequent_value(d: dict) -> tuple:
|
def most_frequent_value(d: dict) -> tuple:
|
||||||
pass
|
frequency = {}
|
||||||
|
for value in d.values():
|
||||||
|
if value in frequency:
|
||||||
|
frequency[value] += 1
|
||||||
|
else:
|
||||||
|
frequency[value] = 1
|
||||||
|
max_value = None
|
||||||
|
max_count = 0
|
||||||
|
for value, count in frequency.items():
|
||||||
|
if count > max_count:
|
||||||
|
max_count = count
|
||||||
|
max_value = value
|
||||||
|
return(max_value, max_count)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(most_frequent_value({"a": 1, "b": 2, "c": 1, "d": 3}))
|
||||||
Loading…
Reference in New Issue
Block a user