mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Merge pull request #35 from edawine/patch-2
Uses 'with' instead of manually closing files
This commit is contained in:
commit
df8798416b
|
@ -17,9 +17,8 @@ def main():
|
||||||
startTime = time.time()
|
startTime = time.time()
|
||||||
allPatterns = {}
|
allPatterns = {}
|
||||||
|
|
||||||
fo = open('Dictionary.txt')
|
with open('Dictionary.txt') as fo:
|
||||||
wordList = fo.read().split('\n')
|
wordList = fo.read().split('\n')
|
||||||
fo.close()
|
|
||||||
|
|
||||||
for word in wordList:
|
for word in wordList:
|
||||||
pattern = getWordPattern(word)
|
pattern = getWordPattern(word)
|
||||||
|
@ -29,9 +28,9 @@ def main():
|
||||||
else:
|
else:
|
||||||
allPatterns[pattern].append(word)
|
allPatterns[pattern].append(word)
|
||||||
|
|
||||||
fo = open('Word Patterns.txt', 'w')
|
with open('Word Patterns.txt', 'w') as fo:
|
||||||
fo.write(pprint.pformat(allPatterns))
|
fo.write(pprint.pformat(allPatterns))
|
||||||
fo.close()
|
|
||||||
totalTime = round(time.time() - startTime, 2)
|
totalTime = round(time.time() - startTime, 2)
|
||||||
print('Done! [', totalTime, 'seconds ]')
|
print('Done! [', totalTime, 'seconds ]')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user