I must create a function that accepts a filename as a string and returns the dictionary contents (a dictionary file linked below) as a set of words
This is my current code (it's quite messy):
def dictWords() : words =  try : fileIn = open('dictionary.txt') for line, value in enumerate(fileIn) : if not line: break words.append(line) print(words) wordList = set(words) except OSError as e : if e.errno == errno.ENOENT: wordList = set() print("File does not exist!") fileIn.close() return wordList dictWords()
The code must also return an empty set if the file is not found or cannot be opened (I am required to use a try/except construct).
I cannot seem to get this code to work and am new to coding so any help would be greatly appreciated. This is the link to the dictionary file if you feel it necessary: http://research.cs.queensu.ca/home/cisc101f/Winter2018/Assn3/corncob_lowercase.txt