如何查看两个字符串列表的匹配百分比?
我是Python的初学者。在这里,我在比较两个列表时遇到了问题。我的第一个问题是不应准确比较列表。但是应该将其与其他列表匹配 70%,如果存在,则返回true。 包含()方法在这种情况下无济于事。这是我的清单:
TotalTags = ["citrus", "orange", "vitamin-C", "sweet", "yellow", "vitamin-A"] #etc
LikedTags = ["citrus", "orange", "vitamin-D"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Sahil Desai的答案中的FuzzyWuzzy图书馆看起来真的很简单。
这是具有基本功能的想法。
fuzzywuzzy library in Sahil Desai's answer looks really simple.
Here is an idea with basic functions.
您可以利用FuzzyWuzzy Python库,
此方法如果您只想匹配项目,则可以直接匹配两个列表的字符,然后可以使用Jaccard相似方法。
you can utilizes fuzzywuzzy python library
This method directly match the characters of the two list if you want to just match the items then you can used Jaccard similarity method.
您可以使用
difflib.Sequecemecematcher
并从下面的两个列表中找到每个两个单词之间的相似性:(输出仅显示两个具有相似性> 70%的单词)
输出:
You can use
difflib.SequenceMatcher
and find similarity between each two word from two list like below: (Output only shows two words that have similarity > 70%)Output:
您还可以使用hundin 代码> 模块
输出:
you can also do something like this with the builtin
collections
moduleoutput: