mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-19 10:48:58 +08:00
Fix ResourceWarning: unclosed file (#681)
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
This commit is contained in:

committed by
Libin Yang

parent
3dc50529ca
commit
2d70e9f747
@ -5,11 +5,10 @@ LETTERS_AND_SPACE = UPPERLETTERS + UPPERLETTERS.lower() + ' \t\n'
|
||||
|
||||
def loadDictionary():
|
||||
path = os.path.split(os.path.realpath(__file__))
|
||||
dictionaryFile = open(path[0] + '/Dictionary.txt')
|
||||
englishWords = {}
|
||||
for word in dictionaryFile.read().split('\n'):
|
||||
englishWords[word] = None
|
||||
dictionaryFile.close()
|
||||
with open(path[0] + '/Dictionary.txt') as dictionaryFile:
|
||||
for word in dictionaryFile.read().split('\n'):
|
||||
englishWords[word] = None
|
||||
return englishWords
|
||||
|
||||
ENGLISH_WORDS = loadDictionary()
|
||||
|
Reference in New Issue
Block a user