Created
November 22, 2015 05:49
-
-
Save mreider/581c533306e80020dd35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import string | |
| def analyze(file): | |
| count = {} | |
| remove = dict.fromkeys(map(ord, string.punctuation)) | |
| f = open(file ,'r') | |
| f = f.read().lower() | |
| f = f.translate(remove) | |
| wordList = f.split() | |
| for word in wordList: | |
| if not count.get(word,None): | |
| count[word] = 1 | |
| else: | |
| count[word] += 1 | |
| totals = {'mostCommonWords':sorted(count, key=count.get, reverse=True), \ | |
| 'leastCommonWords' : sorted(count, key=count.get), \ | |
| 'shortestWord' : min(wordList, key=len), \ | |
| 'longestWord' : max(wordList, key=len) } | |
| return totals | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment