Bag-of-words count vectors

Write codeEasy15 minMeta style

Your task

Build bag-of-words count vectors for a set of documents over a fixed vocabulary. Given docs (a list of documents, each a list of word tokens) and vocab (the ordered vocabulary list, assumed to have no duplicates), return for each document a vector of length len(vocab) where position i is the number of times vocab[i] appears in that document. Words not in the vocabulary are ignored. Return the list of count vectors in document order.

Examples

bag_of_words(docs: list[list[str]], vocab: list[str]) -> list[list[int]]
Example 1
Inputbag_of_words([["a", "b", "a"], ["b", "c"]], ["a", "b", "c"])
Output[[2, 1, 0], [0, 1, 1]]