All problems
Mode
Problem
Return the most frequent value in data. On ties, return the smallest of the tied values. Return None for an empty list.
Hint
Count occurrences with a dictionary, then take the smallest key with the maximum count.
Test cases
case 1
in: [[1,2,2,3]]
expected: 2
case 2
in: [[4,4,2,2,1]]
expected: 2
case 3
in: [[3,1,3,2,3]]
expected: 3
case 4
in: [[7]]
expected: 7
case 5
in: [[-1,-1,2]]
expected: -1
Starter codePython
def mode(data):
# Your code here
pass5 test cases · run your code against them in the editor