2016-08-11 13:43:33 +00:00
|
|
|
import pprint, time
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2016-08-11 13:43:33 +00:00
|
|
|
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])
|
2019-10-05 05:14:13 +00:00
|
|
|
return ".".join(wordPattern)
|
|
|
|
|
2016-08-11 13:43:33 +00:00
|
|
|
|
|
|
|
def main():
|
|
|
|
startTime = time.time()
|
|
|
|
allPatterns = {}
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
with open("Dictionary.txt") as fo:
|
|
|
|
wordList = fo.read().split("\n")
|
2016-08-11 13:43:33 +00:00
|
|
|
|
|
|
|
for word in wordList:
|
|
|
|
pattern = getWordPattern(word)
|
|
|
|
|
|
|
|
if pattern not in allPatterns:
|
|
|
|
allPatterns[pattern] = [word]
|
|
|
|
else:
|
|
|
|
allPatterns[pattern].append(word)
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
with open("Word Patterns.txt", "w") as fo:
|
2016-10-08 17:30:05 +00:00
|
|
|
fo.write(pprint.pformat(allPatterns))
|
|
|
|
|
2016-08-11 13:43:33 +00:00
|
|
|
totalTime = round(time.time() - startTime, 2)
|
2019-10-05 05:14:13 +00:00
|
|
|
print(("Done! [", totalTime, "seconds ]"))
|
|
|
|
|
2016-08-11 13:43:33 +00:00
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
if __name__ == "__main__":
|
2016-08-11 13:43:33 +00:00
|
|
|
main()
|