All problems
Jaccard Token Similarity
Problem
Return the Jaccard similarity of two token lists, treating each list as a set: |intersection| / |union|.
Duplicates are ignored. Return 0.0 when both sets are empty.
Hint
Python sets support intersection with & and union with |.
Test cases
case 1
in: [["a","b","c"],["b","c","d"]]
expected: 0.5
case 2
in: [["a","a","b"],["a","b","b"]]
expected: 1
case 3
in: [[],[]]
expected: 0
case 4
in: [["a","b"],["c","d"]]
expected: 0
case 5
in: [["x"],[]]
expected: 0
Starter codePython
def jaccard_tokens(tokens1, tokens2):
# Your code here
pass5 test cases · run your code against them in the editor