Book Complexity Analysis – Harry Potter vs Project Gutenberg

In this recipe we take a look at simple mechanisms that we might use to measure the complexity of different books. First we take a look at the Harry Potter series to consider whether we can analyse the complexity of the books as the series progresses. Then we take a look at some classics from Project Gutenberg and compare them to modern books to see whether there are any similarities and differences between the two.


We consider 3 different factors as potential ways of measuring book complexity;

  • Sentence Length: Number of words per sentence in a book.
  • Word Variety: Number of different words in the first 50,000 words of a book.
  • Average word length: Average length of all of the words of a book.

Note: We opted against using NLTK (the Natural Language Toolkit) to identify words and sentences in order to keep our scripts simple for beginners. This means that some of our sentence lengths and word lengths might be slightly off.


Click any image to enlarge it.


These findings should be taken with a pinch of salt, given that our scripts for building word and sentence counts aren’t 100% rigorous. With that in mind however, any errors should be relative across all samples, so the overall findings should be reasonable. Given that the Harry Potter books are aimed at teenagers, we expect to see indicators of more complexity from the classics we found on Project Gutenberg. Here is what we found.

  1. Sentence length in the Harry Potter books was noticeably shorter than the classic books we chose from Project Gutenberg.
  2. While Wuthering Heights and Moby Dick had more unique words in the first 50,000 than the Harry Potter books, Pride and Prejudice had fewer than in the first Harry Potter book.
  3. Both sentence length and unique words goes up from the first Harry Potter to the last Harry Potter book. Not significantly, but it does increase with the age of the books.
  4. Average word length appears to be essentially the same across books of all reading ages.

File Downloads

TypeFile NameDate ModifiedSize

all_files_book_analysis_july_2015 2:51 pm 07/26/2015645.5k

common 2:50 pm 07/26/20151.3k

generate_charts 2:50 pm 07/26/20151k

plot_sentence_length 2:50 pm 07/26/20153.6k

plot_word_length 2:50 pm 07/26/20153.7k

plot_word_variety 2:50 pm 07/26/20152.4k


Download the “” file to grab all scripts and related data files for this recipe. Note. We have not included any of the source book data in this sample for copyright reasons, but we have included the intermediate data files required for generating these charts.

A short description of the files follows; Contains some common functions for all of the scripts – mostly related to setting up default styles for the MatPlotLib. A shell script for OSX/Linux that will simply generate all of the above charts in one command. Generates the sentence length charts from previously generated “sentence length” files. Generates the word length charts from previously generated “word summary” files. Plots the word variety chart above. Note. You should use the files in data/50k/, as these all contain information about just the first 50,000 words of each book (as a longer book will naturally have more words in – so we have to normalise them).

utils/: In the utils folder are two scripts for generating text/csv files describing sentence lengths and word counts from a book in text file format.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>