Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-165

Toxicity Lexicon Score

Problem

Return the fraction of tokens that appear in the toxicity lexicon, matching case-insensitively.

Repeated toxic tokens count each time, and an empty token list gives 0.0.

Hint

Lowercase both the tokens and the lexicon entries before comparing.

Test cases

case 1
in: [["you","are","stupid"],["stupid","idiot"]]
expected: 0.3333333333333333
case 2
in: [["good","day"],["bad"]]
expected: 0
case 3
in: [[],["x"]]
expected: 0
case 4
in: [["Stupid","STUPID"],["stupid"]]
expected: 1
Starter codePython
def toxicity_lexicon_score(tokens, lexicon):
    # Your code here
    pass

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