Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

How to solve this python question? I can't figure out at all...this one is stubborn

$
0
0
def average_word_length(text):
""" (list of str) -> float

Precondition: text is non-empty. Each str in text ends with \n and at
least one str in text contains more than just \n.

Return the average length of all words in text. Surrounding punctuation
is not counted as part of the words.

>>> text = ['James Fennimore Cooper\n', 'Peter, Paul and Mary\n']
>>> average_word_length(text)
5.142857142857143
"""

Viewing all articles
Browse latest Browse all 2485

Trending Articles