Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-013

Vocabulary with Minimum Frequency

Problem

Count how often each token occurs and return a dictionary mapping every token whose count is at least min_freq to that count.

Insert tokens in first-occurrence order and include each token once. Return an empty dictionary for empty input.

Hint

Count first, then filter with a second pass over the tokens.

Test cases

case 1
in: [["a","b","a","c","a","b"],2]
expected: {"a":3,"b":2}
case 2
in: [["a","b","a","c","a","b"],3]
expected: {"a":3}
case 3
in: [[],1]
expected: {}
case 4
in: [["x","y","z"],1]
expected: {"x":1,"y":1,"z":1}
Starter codePython
def build_vocab_min_freq(tokens, min_freq):
    # Your code here
    pass

4 test cases · run your code against them in the editor