We will create a function ( avg_sentence_len ) to calculate the average sentence length across a piece of text. This function should take text as an input parameter. Within this function: 1. sentences : Use the split() string method to split the input text at every '.'. This will split the text into a list of sentences. Store this in the variable sentences. To keep things simple, we will consider every "." as a sentence separator. (This decision could lead to misleading answers. For example, "Hello Dr. Jacob." is actually a single sentence, but our function will consider this 2 separate sentences). 2. words : Use the split() method to split the input text into a list of separate words, storing this in words . Again, to limit complexity, we will assume that all words are separated by a single space (" "). (So, while "I am going.to see you later" actually has 7 words, since there is no space after the ".", so we will assume the this to contain 6 separate words in our function.) 3. Calculate the average sentence length, return ing this from your function: 4. if the last value in sentences is an empty string: the average sentence length should be the number of words divided by the len(sentences) - 1. 5. otherwise, the average sentence length should be the number of words divided by the number of sentences . For the "I am going.to see you later" example, your function should return 1.5.
We will create a function ( avg_sentence_len ) to calculate the average sentence length across a piece of text. This function should take text as an input parameter. Within this function: 1. sentences : Use the split() string method to split the input text at every '.'. This will split the text into a list of sentences. Store this in the variable sentences. To keep things simple, we will consider every "." as a sentence separator. (This decision could lead to misleading answers. For example, "Hello Dr. Jacob." is actually a single sentence, but our function will consider this 2 separate sentences). 2. words : Use the split() method to split the input text into a list of separate words, storing this in words . Again, to limit complexity, we will assume that all words are separated by a single space (" "). (So, while "I am going.to see you later" actually has 7 words, since there is no space after the ".", so we will assume the this to contain 6 separate words in our function.) 3. Calculate the average sentence length, return ing this from your function: 4. if the last value in sentences is an empty string: the average sentence length should be the number of words divided by the len(sentences) - 1. 5. otherwise, the average sentence length should be the number of words divided by the number of sentences . For the "I am going.to see you later" example, your function should return 1.5.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
![1c) Average sentence length
We will create a function ( avg_sentence_len ) to calculate the average sentence length across a piece of text.
This function should take text as an input parameter.
Within this function:
1. sentences : Use the split() string method to split the input text at every '."
variable sentences . To keep things simple, we will consider every "." as a sentence separator. (This decision could lead to misleading answers. For
example, "Hello Dr. Jacob." is actually a single sentence, but our function will consider this 2 separate sentences).
2. words : Use the split() method to split the input text into a list of separate words, storing this in words . Again, to limit complexity, we will assume
that all words are separated by a single space (" "). (So, while "I am going.to see you later" actually has 7 words, since there is no space after the ".", so
This will split the text into a list of sentences. Store this in the
we will assume the this to contain 6 separate words in our function.)
3. Calculate the average sentence length, return ing this from your function:
4. if the last value in sentences is an empty string: the average sentence length should be the number of words divided by the len(sentences) - 1.
5. otherwise, the average sentence length should be the number of words divided by the number of sentences .
For the "I am going.to see you later" example, your function should return 1.5.
-]:
1 def avg_sentence_len(text):
File "<ipython-input-1-30796a91074f>", line 3
SyntaxError: unexpected EOF while parsing
assert avg_sentence_len("each sentence. has two. words right?.") == 2
2 assert avg_sentence_len("a. a. a") == avg_sentence_len("a. a. a.")
3 assert avg_sentence_len("a. a. a") == 1
assert avg_sentence_len("hello Dr. Jacob.") == 1.5
assert avg_sentence_len(news_df[ 'message'][0])//1 == 16
assert avg_sentence_len("one. two.") != avg_sentence_len("one.two.")
]:
1.
5](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F5091d76d-12c2-4f11-a524-11cc629346d3%2F78480ae8-ed7b-442c-8137-d7d36e6bdd64%2Fkxqwk3_processed.png&w=3840&q=75)
Transcribed Image Text:1c) Average sentence length
We will create a function ( avg_sentence_len ) to calculate the average sentence length across a piece of text.
This function should take text as an input parameter.
Within this function:
1. sentences : Use the split() string method to split the input text at every '."
variable sentences . To keep things simple, we will consider every "." as a sentence separator. (This decision could lead to misleading answers. For
example, "Hello Dr. Jacob." is actually a single sentence, but our function will consider this 2 separate sentences).
2. words : Use the split() method to split the input text into a list of separate words, storing this in words . Again, to limit complexity, we will assume
that all words are separated by a single space (" "). (So, while "I am going.to see you later" actually has 7 words, since there is no space after the ".", so
This will split the text into a list of sentences. Store this in the
we will assume the this to contain 6 separate words in our function.)
3. Calculate the average sentence length, return ing this from your function:
4. if the last value in sentences is an empty string: the average sentence length should be the number of words divided by the len(sentences) - 1.
5. otherwise, the average sentence length should be the number of words divided by the number of sentences .
For the "I am going.to see you later" example, your function should return 1.5.
-]:
1 def avg_sentence_len(text):
File "<ipython-input-1-30796a91074f>", line 3
SyntaxError: unexpected EOF while parsing
assert avg_sentence_len("each sentence. has two. words right?.") == 2
2 assert avg_sentence_len("a. a. a") == avg_sentence_len("a. a. a.")
3 assert avg_sentence_len("a. a. a") == 1
assert avg_sentence_len("hello Dr. Jacob.") == 1.5
assert avg_sentence_len(news_df[ 'message'][0])//1 == 16
assert avg_sentence_len("one. two.") != avg_sentence_len("one.two.")
]:
1.
5
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education