rare = (["word1","word4","word5"])
freq = (["word1","word2","word3"])
unique = rare.intersection(freq)
print unique
error: AttributeError: ‘list’ object has no attribute ‘intersection’
Am I not creating the sets correctly? They look like the examples in documentation — but I can’t seem to use normal set methods on them.
What is the proper syntax for creating sets if these are lists?
This way you’re not creating sets, just regular lists. Use the
setfunction:Maybe you’re confusing sets with tuples. A tuple is created with expressions between parenthesis, but you must provide at least a comma:
Tuples are like immutable lists, but they’re not sets.