From e51406583c7e45e51f702c09f3e63f9f91a66f9a Mon Sep 17 00:00:00 2001 From: Harshil Darji Date: Thu, 11 Aug 2016 19:13:33 +0530 Subject: [PATCH] Initial --- {detect english => other}/Dictionary.txt | 0 .../detecting_english_programmatically.py | 0 other/word_patterns.py | 39 +++++++++++++++++++ 3 files changed, 39 insertions(+) rename {detect english => other}/Dictionary.txt (100%) rename {detect english => other}/detecting_english_programmatically.py (100%) create mode 100644 other/word_patterns.py diff --git a/detect english/Dictionary.txt b/other/Dictionary.txt similarity index 100% rename from detect english/Dictionary.txt rename to other/Dictionary.txt diff --git a/detect english/detecting_english_programmatically.py b/other/detecting_english_programmatically.py similarity index 100% rename from detect english/detecting_english_programmatically.py rename to other/detecting_english_programmatically.py diff --git a/other/word_patterns.py b/other/word_patterns.py new file mode 100644 index 000000000..b5bf02836 --- /dev/null +++ b/other/word_patterns.py @@ -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()