All problems
Jaccard Index of Sets
Problem
The Jaccard index is |A intersect B| / |A union B| over unique elements. Return 1.0 when both sets are empty.
Given two lists of elements, return the index.
Hint
Deduplicate before comparing.
Test cases
case 1
in: [[1,2],[2,3]]
expected: 0.3333333333333333
case 2
in: [[1,1,2],[1,2,2]]
expected: 1
case 3
in: [[1,2],[3,4]]
expected: 0
Starter codePython
def jaccard_index_of_sets(a, b):
# Your code here
pass3 test cases · run your code against them in the editor