I have two list like this:
listt = [["a","abc","zzz","xxx","abc","abc"],["yyy","ggg","abc","cccc"]]
I have another queryList like this:
queryList = ["abc","cccc","abc","yyy"]
queryList & listt[0] contain 2 "abc" in common.
queryList & listt[1] contain 1 "abc", 1 "cccc" & 1 "yyy" in common.
So I want an output like this:
[2,3] #2 = Total common items between queryList & listt[0]
#3 = Total common items between queryList & listt[1]
I am currently using loops to do this, but this seems to be slow. I will have millions of lists, with thousands of items per list.
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)