我有两个像这样的列表:
listt = [["a","abc","zzz","xxx","abc","abc"],["yyy","ggg","abc","cccc"]]
我有另一个类似这样的查询列表:
queryList = ["abc","cccc","abc","yyy"]
queryList
和listt[0]
共有2个"abc"
。
queryList
和listt[1]
共有1个"abc"
,1个"cccc"
和1个"yyy"
。
因此,我希望输出结果如下:
[2,3] #2 = Total common items between queryList & listt[0]
#3 = Total common items between queryList & listt[1]
目前我正在使用循环来完成这个任务,但似乎速度很慢。我会有数百万个列表,每个列表中有数千个项目。
listt = [["a","abc","zzz","xxx","abc","abc"],["yyy","ggg","abc","cccc"]]
queryList = ["abc","cccc","abc","yyy"]
totalMatch = []
for hashtree in listt:
matches = 0
tempQueryHash = queryList.copy()
for hash in hashtree:
for i in range(len(tempQueryHash)):
if tempQueryHash[i]==hash:
matches +=1
tempQueryHash[i] = "" #Don't Match the same block twice.
break
totalMatch.append(matches)
print(totalMatch)