Be aware that you're get_average_sentence_length function is actually returning the average number of characters per word in the sentence that you pass. Something more desirable would be the average number of words per sentence or the average number of characters per sentence.
There's likely to be much less difference between the number of characters per word among the letters because of the average length of a word in English is about 5.1. You see this minor difference in your output
Finally, a comment on your build_frequency_table function. You're looping through the corpus twice unnecessarily. First to initialize all the elements to zero and then to increment the values in the dictionary. You can do this all in one iteration:
for word in corpus:
if word in frequency_table:
frequency_table[word] += 1
else:
frequency_table[word] = 1
Be aware that you're
get_average_sentence_length
function is actually returning the average number of characters per word in the sentence that you pass. Something more desirable would be the average number of words per sentence or the average number of characters per sentence.There's likely to be much less difference between the number of characters per word among the letters because of the average length of a word in English is about
5.1
. You see this minor difference in your outputFinally, a comment on your
build_frequency_table
function. You're looping through the corpus twice unnecessarily. First to initialize all the elements to zero and then to increment the values in the dictionary. You can do this all in one iteration: