Turning a list into a set - Python

Viewed 15221

I wanted to print a set of lines in a file that start with a certain character (here it's "c"), but I get an error whenever I try to convert a list into a set

I have the following code:

z = open("test.txt", "r")
wordList = [line.rstrip().split() for line in z if line.startswith(("c"))]
wordList = set(wordList)
print(wordList)

Here is the error I get:

Traceback (most recent call last):
   wordList = set(wordList)
TypeError: unhashable type: 'list'
2 Answers
Related