def relative_distance(a_str, b_str):
 set_a = set(a_str.split(' '))
 set_b = set(b_str.split(' '))
 if (min(len(set_a), len(set_b)) in (0, 1)):
  return difflib.SequenceMatcher(None, a_str, b_str).quick_ratio()
 return ((1.0 * len(set_a.intersection(set_b))) / max(len(set_a), len(set_b)))

def relative_distance ( a_str , b_str ) : set_a = set ( a_str . split ( ' ' ) ) set_b = set ( b_str . split ( ' ' ) ) if ( min ( len ( set_a ) , len ( set_b ) ) in ( 0 , 1 ) ) : return difflib . SequenceMatcher ( None , a_str , b_str ) . quick_ratio ( ) return ( ( 1.0 * len ( set_a . intersection ( set_b ) ) ) / max ( len ( set_a ) , len ( set_b ) ) )
measures the "similarity" of the strings .