I’ve got below chunk and I need to define ‘Score’ as the intersection / union for each set of words in any given two lists. I understand & and | could only be used in sets. From studytonight I get that below code shoud work but it’s gving me > TypeError: unhashable type: ‘list’
JavaScript
x
7
1
corpus = [
2
["i","did","not","like","the","service"],
3
["the","service","was","ok"],
4
["i","was","ignored","when","i","asked","for","service"]
5
]
6
{corpus[0],corpus[1],corpus[2]}
7
Could someone please correct my mistake?
JavaScript
1
6
1
# This is my goal - but all in 1 set
2
set1 = {"i","did","not","like","the","service"}
3
set2 = {"the","service","was","ok"}
4
set3 = {"i","was","ignored","when","i","asked","for","service"}
5
set1&set3
6
JavaScript
1
9
1
# Even like this it gives the same error, wwhy can't I do it?
2
set = {
3
["i","did","not","like","the","service"],
4
["the","service","was","ok"],
5
["i","was,"ignored","when","i","asked","for","service"]
6
7
8
}
9
Advertisement
Answer
You should use:
JavaScript
1
3
1
data = list(sum(corpus, [])) # this will convert 2d into single D list
2
result = set(data)
3
or
JavaScript
1
2
1
results = set(list(sum(corpus, [])))
2