Skip to content

Instantly share code, notes, and snippets.

@neilkod
Created June 10, 2010 11:30
Show Gist options
  • Save neilkod/432852 to your computer and use it in GitHub Desktop.
Save neilkod/432852 to your computer and use it in GitHub Desktop.
# not my code but very similar to what i'm trying to accomplish
"""
Formula:
Na = number of set A elements
Nb = number of set B elements
Nc = number of common items
T = Nc / (Na + Nb - Nc)
"""
def tanimoto(a, b):
c = [v for v in a if v in b]
return float(len(c)) / (len(a)+len(b)-len(c))
def name_compare(name1, name2):
return tanimoto(name1, name2)
>>> name_compare("James Brown", "Brown, James")
0.91666666666666663
>>> name_compare("Berry Tsakala", "Bernard Tsakala")
0.75
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment