Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
harshildarji committed Aug 11, 2016
1 parent 1376e3c commit e514065
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
39 changes: 39 additions & 0 deletions other/word_patterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pprint, time

def getWordPattern(word):
word = word.upper()
nextNum = 0
letterNums = {}
wordPattern = []

for letter in word:
if letter not in letterNums:
letterNums[letter] = str(nextNum)
nextNum += 1
wordPattern.append(letterNums[letter])
return '.'.join(wordPattern)

def main():
startTime = time.time()
allPatterns = {}

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

for word in wordList:
pattern = getWordPattern(word)

if pattern not in allPatterns:
allPatterns[pattern] = [word]
else:
allPatterns[pattern].append(word)

fo = open('Word Patterns.txt', 'w')
fo.write(pprint.pformat(allPatterns))
fo.close()
totalTime = round(time.time() - startTime, 2)
print('Done! [', totalTime, 'seconds ]')

if __name__ == '__main__':
main()

0 comments on commit e514065

Please sign in to comment.