In: Computer Science
Python class
Select a free ebook on gutenberg . org and download the plain
text file...
Python class
Select a free ebook on gutenberg . org and download the plain
text file (utf8). the ebook is (The Devil's Dictionary by Ambrose
Bierce)
Write a program that does the following:
- Read in your ebook (any book, any language)
- Break the book into words (look at .split() for strings)
- Make a dictionary of all words and how often they occur: for
instance if the word'the'happened 2000 time and the word'a'
happened 1940 times word_dict= {'the' : 2000, 'a' :1940}
- Print the dictionary of word frequencies to a file (freqs.txt)
with the most frequent at the top and least frequent at the
bottom
- No need to submit the book, I will run it on my own files.
Turn in a .py or Google Colab URL
Dictionaries are not easily sortable since they are not ordered
like a list. To sort for this assignment use the following
template.
import operator
sorted_dict =
sorted(my_dict.items(),key=operator.itemgetter(1))