All problems
Bag of Words Vector
Problem
The bag-of-words vector counts token occurrences against a fixed vocabulary, ignoring order.
Given the vocabulary and tokens, return the count vector.
Hint
Out-of-vocabulary tokens are ignored.
Test cases
case 1
in: [["a","b","c"],["a","a","c"]]
expected: [2,0,1]
case 2
in: [["x"],["x","x","x"]]
expected: [3]
case 3
in: [["m"],[]]
expected: [0]
Starter codePython
def bag_of_words_vector(vocab, tokens):
# Your code here
pass3 test cases · run your code against them in the editor