I am a beginner at python. Here I had a problem with comparing two lists. My first problem is the list should not be compared exactly. But It should be compared about 70% matching with other list and return true if exist. contains() method doesn't help in this case. Here is my list:

TotalTags = ["citrus", "orange", "vitamin-C", "sweet", "yellow", "vitamin-A"] #etc
LikedTags = ["citrus", "orange", "vitamin-D"]

推荐答案

fuzzywuzzy library in Sahil Desai's answer looks really simple.

Here is an idea with basic functions.

TotalTags = ["citrus", "orange", "vitamin-C", "sweet", "yellow", "vitamin-A"] #etc
LikedTags = ["citrus", "orange", "vitamin-C", "sweet", "yellow"]

print(len(set(TotalTags).intersection(set(LikedTags))) / len(TotalTags))  # 0.8333333
print(sum([True for x in TotalTags if x in LikedTags]) / len(TotalTags))  # 0.8333333

Python相关问答推荐

在Google Colab中设置Llama-2出现问题-加载判断点碎片时Cell-run失败

为什么符号没有按顺序添加?

图像 pyramid .难以创建所需的合成图像

更改键盘按钮进入'

从dict的列中分钟

数据抓取失败:寻求帮助

django禁止直接分配到多对多集合的前端.使用user.set()

提取相关行的最快方法—pandas

如何在turtle中不使用write()来绘制填充字母(例如OEG)

如何启动下载并在不击中磁盘的情况下呈现响应?

如何在Gekko中使用分层条件约束

处理Gekko的非最优解

在电影中向西北方向对齐""

Python将一个列值分割成多个列,并保持其余列相同

如何训练每一个pandaprame行的线性回归并生成斜率

如何在Python中从html页面中提取html链接?

按最大属性值Django对对象进行排序

了解如何让库认识到我具有所需的依赖项

Python键盘模块不会立即检测到按键

判断字典中是否有多个值对