pltrey / python

0 stars 0 forks source link

Comments #1

Open zjedwin opened 6 years ago

zjedwin commented 6 years ago

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

murderer 4.144578313253012
lily 4.099667774086379
myrtle 4.380952380952381
gregg 4.51980198019802

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
pltrey commented 6 years ago

Could you tell me what's wrong with my get_average_sentence_length function?