Remove every token that appears in stopwords. Comparisons are case-sensitive, and retained tokens must remain in their original order. Return a new list without modifying either input.
Input: tokens = ["this", "is", "a", "test"], stopwords = ["is", "a"]
Output: ["this", "test"]
Explanation: The two matching stopwords are removed while the remaining order is preserved.
Input: tokens = ["hello", "world"], stopwords = ["the", "and"]
Output: ["hello", "world"]
Input: tokens = ["a", "an", "the"], stopwords = ["a", "an", "the"]
Output: []
Build blocked = set(stopwords) before scanning the tokens.
Filter with [token for token in tokens if token not in blocked].
Sign in to take notes on this problem
Accepts: array
Accepts: array
Remove every token that appears in stopwords. Comparisons are case-sensitive, and retained tokens must remain in their original order. Return a new list without modifying either input.
Input: tokens = ["this", "is", "a", "test"], stopwords = ["is", "a"]
Output: ["this", "test"]
Explanation: The two matching stopwords are removed while the remaining order is preserved.
Input: tokens = ["hello", "world"], stopwords = ["the", "and"]
Output: ["hello", "world"]
Input: tokens = ["a", "an", "the"], stopwords = ["a", "an", "the"]
Output: []
Build blocked = set(stopwords) before scanning the tokens.
Filter with [token for token in tokens if token not in blocked].
Sign in to take notes on this problem
Accepts: array
Accepts: array