For reference, here is your get_average_sentence_length() function:
def get_average_sentence_length(text):
text = text.replace('!', '.')
text = text.replace('?', '.')
sentences_in_text = text.split('.')
word_count_list = []
for sentence in sentences_in_text:
word_count = 0
for word in sentence.split():
word_count += 1
word_count_list.append(word_count)
return sum(word_count_list)/len(sentences_in_text)
Note that when we split on the final period in each text sample, a blank "sentence" will be added to the end of sentences_in_text, and this "sentence" of length zero will throw off our calculations. We can account for this by modifying the 'sentences_in_text = text.split('.')' line to omit the final 'sentence' in the split using list notation, like so:
For reference, here is your get_average_sentence_length() function:
Note that when we split on the final period in each text sample, a blank "sentence" will be added to the end of sentences_in_text, and this "sentence" of length zero will throw off our calculations. We can account for this by modifying the 'sentences_in_text = text.split('.')' line to omit the final 'sentence' in the split using list notation, like so: