Сначала вы получаете список строк, разделенных .
Затем вы получаете фразы, разделенные ,
Затем вы получаете слова в каждой фразе, разделенные space
Затем вы получаете сумму длин каждого слова и делите на общее количество слов
text = "On Saturday, September 17 at 8:30 pm EST, an explosion rocked West 23 Street in Manhattan, in the neighborhood commonly referred to as Chelsea, injuring 29 people, smashing windows and initiating street closures. There were no fatalities. Officials maintain that a homemade bomb, which had been placed in a dumpster, created the explosion."
lines = text.strip('.').split('.')
print("There are", len(lines), "lines present")
for line in lines:
phrases = line.split(',')
phrases = [phrase.strip() for phrase in phrases]
words = [phrase.split() for phrase in phrases]
lengths = [len(word) for word in words]
print(f"{sum(lengths)}/{len(lengths)}={sum(lengths)/len(lengths)}")
Вывод:
There are 3 lines present
33/6=5.5
4/1=4.0
16/3=5.333333333333333