def map_strings(set_keys,
set_values,
cutoff=0.8,
ignore_no_matches=True):
"""Map a set of secondary strings to a set of primary strings."""
N = 1
CUTOFF = cutoff
def get_matches(x):
"""Help to get matches."""
result_list = difflib.get_close_matches(
x, set_values, n=N, cutoff=CUTOFF)
if ignore_no_matches:
if result_list:
return result_list[0]
else:
return ''
else:
return result_list[0]
mapper = map(lambda x: (x, get_matches(x)),
set_keys)
return dict(mapper)
评论列表
文章目录