Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-036

Dice Coefficient of Tokens

Problem

Return the Dice coefficient of two token lists, treating each list as a set: 2 * |intersection| / (|A| + |B|).

Duplicates are ignored. Return 0.0 when both sets are empty.

Hint

Double the intersection size, then divide by the sum of both set sizes.

Test cases

case 1
in: [["a","b","c"],["b","c","d"]]
expected: 0.6666666666666666
case 2
in: [["a","a","b"],["a","b","b"]]
expected: 1
case 3
in: [[],[]]
expected: 0
case 4
in: [["a"],["b"]]
expected: 0
case 5
in: [["x"],[]]
expected: 0
Starter codePython
def dice_tokens(tokens1, tokens2):
    # Your code here
    pass

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