Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-009

Stopword Removal

Problem

Remove every token that appears in the stopwords list.

Preserve the order and any duplicates of the remaining tokens, and return an empty list when everything is filtered out.

Hint

Convert the stopwords to a set for O(1) membership checks.

Test cases

case 1
in: [["the","cat","is","on","the","mat"],["the","is","on"]]
expected: ["cat","mat"]
case 2
in: [["a","b","c"],[]]
expected: ["a","b","c"]
case 3
in: [[],["x"]]
expected: []
case 4
in: [["do","not","stop"],["not","stop","never"]]
expected: ["do"]
Starter codePython
def remove_stopwords(tokens, stopwords):
    # Your code here
    pass

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