Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-046

Wildcard Prefix Match

Problem

Return the sorted list of vocabulary words that start with prefix.

An empty prefix matches every word. Matching is case-sensitive.

Hint

str.startswith handles both the general case and the empty prefix.

Test cases

case 1
in: [["apple","app","banana","apricot"],"ap"]
expected: ["app","apple","apricot"]
case 2
in: [["a","b"],""]
expected: ["a","b"]
case 3
in: [["x"],"y"]
expected: []
case 4
in: [[],"a"]
expected: []
case 5
in: [["Cat","cat"],"c"]
expected: ["cat"]
Starter codePython
def wildcard_prefix_match(vocab, prefix):
    # Your code here
    pass

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