SomePythonPackages

fansichao 2021-10-23 16:16:35
Categories: Tags:

tags: 202101

difflib

difflib 高性能模糊搜索,模糊搜索优化

使用样例

1
2
3
4
5
6
7
8
9
10

import difflib

lis = ['哈哈', '呵呵', '啦啦', '嘻嘻', '乐乐', '快快乐乐', '乐乐高']
res = difflib.get_close_matches('乐乐', lis, 3, cutoff=0.6)

第一个参数:搜索的关键词,
第二个参数:待搜索的List,
第三个参数:搜索出来结果的个数
第四个参数(cutoff): 匹配度,模糊搜索一般调0.6就可以了,越大越精确

Resources