All problems
Label Encoding from Names
Problem
Map class names to integer ids.
Assign ids in order of first appearance (0, 1, 2, ...) and return the encoded list. An empty input returns [].
Test cases
case 1
in: [["cat","dog","cat","bird"]]
expected: [0,1,0,2]
case 2
in: [["a"]]
expected: [0]
case 3
in: [[]]
expected: []
case 4
in: [["b","a","b","a"]]
expected: [0,1,0,1]
Starter codePython
def encode_labels(names):
# Your code here
pass4 test cases · run your code against them in the editor