for loop - Unable to pass dictionary to function in Python -


i trying match word list index (stored in csv) have using fuzzy matching. load index dictionary. create function compare 2 strings given. if ratio matched larger threshold, return index , indexed string.

this have tried.

def fuzzy_token_set_matching(index_dict, str_for_comparison):     matching_threshold = 70       #if try dict size here, it's 0     print(len(index_dict))           index, indexed_string in index_dict.items():                max_ratio = 0         #compare 2 string using fuzzy matching         fuzz_matching_ratio = fuzz.token_sort_ratio(indexed string, str_for_comparison)                 if fuzz_matching_ratio > max_ratio:             max_ratio = fuzz_matching_ratio                          if max_ratio > matching_threshold:                 return index_index, title                             else:                 return none  input_file = 'index.csv' output_file = 'results.csv'  #load index list dictionary open(input_file, mode = 'r') index_infile:     index_reader = csv.reader(index_infile)     index_dict = {rows[0]:rows[2] rows in index_reader}  print(fuzz.token_sort_ratio(index_dict, 'test'))  >>> results return: 0  

i getting 0 though have exact match should give me matching ratio of 100. reasons unable pass dictionary function.

i guess calling wrong function. fuzz.token_sort_ratio(index_dict, 'test') not fuzzy_token_set_matching(index_dict, str_for_comparison).

so should try following instead:

print(fuzzy_token_set_matchin(index_dict, 'test')) 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -