Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-330

Stopword Removal Order Preserved

Problem

Stopword removal filters tokens in place without reordering the remaining terms.

Given tokens and a stopword list, return the tokens not in the stopword set, preserving order.

Hint

Build a set for O(1) membership tests.

Test cases

case 1
in: [["the","cat","sat"],["the"]]
expected: ["cat","sat"]
case 2
in: [["a","b","c"],["a","c"]]
expected: ["b"]
case 3
in: [["x"],[]]
expected: ["x"]
Starter codePython
def stopword_removal_order_preserved(tokens, stopwords):
    # Your code here
    pass

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