All problems
Dictionary Encoding Build
Problem
Build a dictionary encoding for a column of values.
The dictionary stores each distinct value once in first-appearance order, and the encoded column holds the dictionary index for every input value.
Return [dictionary, encoded_values].
Hint
The dictionary index is simply the number of distinct values seen so far.
Test cases
case 1
in: [["b","a","b","c","a"]]
expected: [["b","a","c"],[0,1,0,2,1]]
case 2
in: [[]]
expected: [[],[]]
case 3
in: [[1,1]]
expected: [[1],[0,0]]
case 4
in: [["x","y","z"]]
expected: [["x","y","z"],[0,1,2]]
Starter codePython
def dictionary_encode(values):
# Your code here
pass4 test cases · run your code against them in the editor