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
添加回答
舉報