Python 比较列表并获取每个元素的匹配百分比
我有两个python列表Python 比较列表并获取每个元素的匹配百分比,python,Python,我有两个python列表 A= ['today is sunday', 'today is wednesday'] B= ['today is sunday', 'today is Monday'....'today is Saturday'] For elm in A: If elm in B: print ("not ok") else: print ("ok") 我想计算两个py
A= ['today is sunday', 'today is wednesday']
B= ['today is sunday', 'today is
Monday'....'today is Saturday']
For elm in A:
If elm in B:
print ("not ok")
else:
print ("ok")
我想计算两个python列表中元素的匹配百分比
A= ['today is sunday', 'today is wednesday']
B= ['today is sunday', 'today is
Monday'....'today is Saturday']
For elm in A:
If elm in B:
print ("not ok")
else:
print ("ok")
所需的匹配百分比计算如图所示:
它可以是:
A= ['today is sunday', 'today is wednesday']
B= ['today is sunday', 'today is monday', 'today is Saturday']
match_percent = (len(set(B).intersection(set(A))))/len(B)*100
print(match_percent)
我不确定您要计算的匹配百分比,所以我冒昧地计算为match\u count/maxlist\u a\u size,list\u b\u size 输出:
0.3333333333333333