All problems
Vocabulary Coverage of Corpus
Problem
Return the type-level coverage: the fraction of distinct tokens in the corpus that appear in vocab.
Duplicate occurrences do not affect the result. Return 0.0 when the corpus has no tokens.
Hint
Coverage is a type-level measure, so work with set(tokens).
Test cases
case 1
in: [["a","b","c","d"],["a","b"]]
expected: 0.5
case 2
in: [["a","a","b"],["a","b"]]
expected: 1
case 3
in: [[],["a"]]
expected: 0
case 4
in: [["x","y"],[]]
expected: 0
Starter codePython
def vocab_coverage(tokens, vocab):
# Your code here
pass4 test cases · run your code against them in the editor