All problems
Frequency Encoding
Problem
Frequency-encode categories by their occurrence count.
Return a dict mapping str(category) to its count. Empty input returns {}.
Hint
Count each distinct category and stringify the keys.
Test cases
case 1
in: [["a","b","a","c","a"]]
expected: {"a":3,"b":1,"c":1}
case 2
in: [[1,1,1]]
expected: {"1":3}
case 3
in: [["x","y","x"]]
expected: {"x":2,"y":1}
case 4
in: [[]]
expected: {}
Starter codePython
def frequency_encode(categories):
# Your code here
pass4 test cases · run your code against them in the editor