python_utilities.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:data_utilities 作者: fmv1992 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号