how to count average sentence length (in words) from a text file contains 100 sentences using python [closed]

The naive way:

sents = text.split('.')
avg_len = sum(len(x.split()) for x in sents) / len(sents)

The serious way: use nltk to tokenize the text according to the target language rules.

Browse More Popular Posts

Leave a Comment