Skip to content

Commit

Permalink
Merge pull request TheAlgorithms#35 from edawine/patch-2
Browse files Browse the repository at this point in the history
Uses 'with' instead of manually closing files
  • Loading branch information
harshildarji authored Oct 8, 2016
2 parents cebbf56 + d8a6245 commit df87984
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions other/word_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ def main():
startTime = time.time()
allPatterns = {}

fo = open('Dictionary.txt')
wordList = fo.read().split('\n')
fo.close()
with open('Dictionary.txt') as fo:
wordList = fo.read().split('\n')

for word in wordList:
pattern = getWordPattern(word)
Expand All @@ -29,9 +28,9 @@ def main():
else:
allPatterns[pattern].append(word)

fo = open('Word Patterns.txt', 'w')
fo.write(pprint.pformat(allPatterns))
fo.close()
with open('Word Patterns.txt', 'w') as fo:
fo.write(pprint.pformat(allPatterns))

totalTime = round(time.time() - startTime, 2)
print('Done! [', totalTime, 'seconds ]')

Expand Down

0 comments on commit df87984

Please sign in to comment.