I’m trying to define Score as the intersection / union for each set of words in any given two lists. I understand that union and intersections are only available for set type of container and I’ve struggled so bad to be able to set it right but haven’t been able to, could someone please help?
corpus = [
["i","did","not","like","the","service"],
["the","service","was","ok"],
["i","was","ignored","when","i","asked","for","service"]
]
tags = ["a","b","c"]
dct_keys = {
"a":1,
"b":2,
"c":3
}
corpus_tags = list(zip(corpus,tags))
from itertools import combinations
my_keys = list(combinations(tags, 2))
goal_dct = {}
for i in range(len(my_keys)):
goal_dct[(my_keys[i])] = {"id_alpha":(dct_keys[my_keys[i][0]]),
"id_beta" :(dct_keys[my_keys[i][1]]),
"socore" : 1}
print(goal_dct)
This is what I’m trying to define as score, to set the example:
set1 = {"i","did","not","like","the","service"}
set2 = {"the","service","was","ok"}
set3 = {"i","was","ignored","when","i","asked","for","service"}
(len(set1)&len(set3))/(len(set1)|len(set3))
>Solution :
Make sets from your lists.
set1 = set(some_list)
set2 = set(other_list)
common_items = set1.intersection(set2)