All problems
Binary Bag of Words Vector
Problem
The binary bag-of-words representation marks presence rather than counts.
Given the vocabulary and tokens, return a 0/1 vector.
Hint
Set the position instead of incrementing.
Test cases
case 1
in: [["a","b","c"],["a","a","c"]]
expected: [1,0,1]
case 2
in: [["x","y"],["y"]]
expected: [0,1]
case 3
in: [["m"],[]]
expected: [0]
Starter codePython
def binary_bag_of_words_vector(vocab, tokens):
# Your code here
pass3 test cases · run your code against them in the editor