A simple command-line tool that analyzes a text file and reports word count and letter frequency. My first Boot.dev project.
Point it at a .txt file and it will:
- Count the total number of words
- Count how many times each letter appears
- Print the letters sorted from most to least frequent
python3 main.py books/frankenstein.txtSample output:
============ BOOKBOT ============
Analyzing book found at books/frankenstein.txt.
----------- Word Count ----------
Found 75767 total words
--------- Character Count -------
e: 44538
t: 29493
a: 25894
o: 24494
i: 23927
...
============= END ===============
A few sample books (Frankenstein, Moby Dick, Pride and Prejudice) are included in books/ to try it out on.
stats.get_book_textreads the file into a string.stats.get_num_wordssplits on whitespace and counts the words.stats.get_char_countbuilds a dictionary of character โ count (case-insensitive).stats.sort_char_countconverts that into a list of{char, num}entries sorted by frequency.stats.analyzeties it all together and prints the report, filtering the output down to alphabetic characters only.
No dependencies beyond the Python standard library.
python3 main.py <path_to_book>