def dice_coefficient(string1, string2):
 def bigrams(s):
  return set((s[i:(i + 2)] for i in xrange((len(s) - 1))))
 nx = bigrams(string1)
 ny = bigrams(string2)
 nt = nx.intersection(ny)
 return ((2.0 * len(nt)) / ((len(nx) + len(ny)) or 1))

def dice_coefficient ( string1 , string2 ) : def bigrams ( s ) : return set ( ( s [ i : ( i + 2 ) ] for i in xrange ( ( len ( s ) - 1 ) ) ) ) nx = bigrams ( string1 ) ny = bigrams ( string2 ) nt = nx . intersection ( ny ) return ( ( 2.0 * len ( nt ) ) / ( ( len ( nx ) + len ( ny ) ) or 1 ) )
returns the similarity between string1 and string1 as a number between 0 .