Jaccard and Dice similarity

Write codeEasy15 min

Your task

Given two lists of items (which may contain duplicates), compute the Jaccard similarity and the Dice (Sorensen) coefficient of their distinct-element sets. Jaccard = |A intersect B| / |A union B|, and Dice = 2*|A intersect B| / (|A| + |B|), where A and B are the sets of distinct items. If both sets are empty (union empty), define both similarities as 1.0. Return [jaccard, dice], each rounded to 4 decimals.

Examples

jaccard_dice(a: list, b: list) -> list[float]
Example 1
Inputjaccard_dice([1, 2, 3], [2, 3, 4])
Output[0.5, 0.6667]