All pastes #2110865 Raw Edit

Someone

public text v1 · immutable
#2110865 ·published 2012-02-07 16:28 UTC
rendered paste body

def jaccardsim(s1, s2): #s1 and s2 are strings
	#Approach: Count the number of common elements, then divide by the union
	uniqueset = []
	commonset = []
	for i in range(0, len(s1)):
		if (not(s1[i] in uniqueset)):
			uniqueset.append(s1[i])
			if ((s1[i] in s2) and not(s1[i] in commonset)):
				commonset.append(s1[i])
	for j in range(0, len(s2)):
		if not(s2[j] in uniqueset):
			uniqueset.append(s2[j])
	return len(commonset)/float(len(uniqueset))