Skip to content

Commit d56b44f

Browse files
author
Gökhan Ercan
committed
Removed redundant intersection loop
Since we already have the set union, calculating the intersection length is possible without looping like this: |A|+|B|-U(A,B). As already implemented in the Jaccard measure.
1 parent 3c42c73 commit d56b44f

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

strsimpy/sorensen_dice.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,5 @@ def similarity(self, s0, s1):
4444
union.add(k)
4545
for k in profile1.keys():
4646
union.add(k)
47-
inter = 0
48-
for k in union:
49-
if k in profile0.keys() and k in profile1.keys():
50-
inter += 1
47+
inter = int(len(profile0.keys()) + len(profile1.keys()) - len(union))
5148
return 2.0 * inter / (len(profile0) + len(profile1))

0 commit comments

Comments
 (0)