Excellent, Sherlock! However, our
get_words_list() function returns the list of all the words. Some of them appear twice, or thrice in the list.
Now we would like to find the list of unique words, so that each word appears only once in the list. How can we do that? We can use the
set() function to create a set data structure. Sets contain no duplicates and are therefore great for finding unique elements. Here's how you can create a set:
with open('filename.txt') as file:
file_data = file.read() # we read all contents of the 'filename.txt'
file_words_list = file_data.split() # we split the contents into the list
unique_words = set(file_words_list) # we cast the list into a set