本篇文章小编给大家分享一下Python3中FuzzyWuzzy库代码实例用法,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
前置条件
Python3
python-Levenshtein
安装方法:
通过Pip安装
pip install fuzzywuzzy
导入库:
fromfuzzywuzzy import fuzz
做个简单的测试:
fuzz.ratio("Let'sdo a simple test", "Let us do a simple test")
如结果所示,“93”表示这两个字符串有93%的相似性,这相当高了。
当有一个字符串列表,想要搜索所有的字符串,FuzzyWuzzy将帮助提取最相关的字符串及其相似性。
fromfuzzywuzzy import processchoices = ["Data Visualisation", "DataVisualization", "Customised Behaviours", "CustomizedBehaviors"]process.extract("data visulisation", choices,limit=2) process.extract("custom behaviour", choices, limit=2)