Merge pull request #35 from edawine/patch-2

Uses 'with' instead of manually closing files
This commit is contained in:
Harshil 2016-10-08 23:01:42 +05:30 committed by GitHub
commit df8798416b

View File

@ -17,9 +17,8 @@ def main():
startTime = time.time()
allPatterns = {}
fo = open('Dictionary.txt')
with open('Dictionary.txt') as fo:
wordList = fo.read().split('\n')
fo.close()
for word in wordList:
pattern = getWordPattern(word)
@ -29,9 +28,9 @@ def main():
else:
allPatterns[pattern].append(word)
fo = open('Word Patterns.txt', 'w')
with open('Word Patterns.txt', 'w') as fo:
fo.write(pprint.pformat(allPatterns))
fo.close()
totalTime = round(time.time() - startTime, 2)
print('Done! [', totalTime, 'seconds ]')