Skip to content

build a set from 3 lists – Python

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’

corpus = [

Could someone please correct my mistake?

# This is my goal - but all in 1 set
set1 = {"i","did","not","like","the","service"}
set2 = {"the","service","was","ok"}
set3 = {"i","was","ignored","when","i","asked","for","service"}
# Even like this it gives the same error, wwhy can't I do it?
set = {




You should use:

data = list(sum(corpus, [])) # this will convert 2d into single D list
result = set(data)


results = set(list(sum(corpus, [])))
User contributions licensed under: CC BY-SA
5 People found this is helpful