All problems
Vocabulary Index Mapping
Problem
Return a dictionary mapping each token in vocab to its integer index in the list.
Indices start at 0 and follow the order of vocab.
Hint
enumerate gives you both the index and the token.
Test cases
case 1
in: [["a","b","c"]]
expected: {"a":0,"b":1,"c":2}
case 2
in: [["the","cat"]]
expected: {"the":0,"cat":1}
case 3
in: [[]]
expected: {}
case 4
in: [["one","two","three","four"]]
expected: {"one":0,"two":1,"three":2,"four":3}
Starter codePython
def vocab_index(vocab):
# Your code here
pass4 test cases · run your code against them in the editor