2 回答
TA贡献1772条经验 获得超5个赞
有可能 :
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)
TA贡献1797条经验 获得超6个赞
我不确定您想要计算的确切匹配百分比,因此我冒昧地计算为match_count / max(list_a_size, list_b_size)。
def intersection(lst1, lst2):
lst3 = [value for value in lst1 if value in lst2]
return len(lst3)
def maximum(a, b):
if a >= b:
return a
else:
return b
A= ['today is sunday', 'today is wednesday']
B= ['today is sunday', 'today is Monday', 'today is Saturday']
match_percent = intersection(A, B) / maximum(len(A),len(B))
print(match_percent)
输出:
0.3333333333333333
添加回答
举报