Created
November 13, 2014 22:25
-
-
Save techvet/47c7e98381a4a14c95e0 to your computer and use it in GitHub Desktop.
Lamdba shortcut
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 | |
| file_in = open('alice_in_wonderland.dat', 'r') | |
| empty_list = [] | |
| read_file = file_in.read() | |
| normalized_string = read_file.translate(None, string.punctuation).lower().replace("\n", " ") | |
| story_words = normalized_string.split() | |
| unique_words = set(story_words) | |
| for word in unique_words: | |
| word_count = story_words.count(word) | |
| empty_list.append((word, word_count)) | |
| endlist = sorted(empty_list, key=lambda x: x[1], reverse=True) | |
| final_list = endlist[:20] | |
| asterisk_count = 20 | |
| for word in final_list: | |
| print "|Word:|", word[0] + ' |Frequency:| ', '*' * asterisk_count | |
| asterisk_count -= 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment