QuestionQuestion

Given the following list of sentences, do the operations listed below. The goals will be to count the number of words in each sentence, the number of times the letter "e" is in each sentence, for each sentence the number of times "e" occurs per word, and the minimum and maximum per-word frequencies of "e" across sentences.

list_of_sentences = [\'Once upon a time\',
\'in a far off kingdom\',
\'lived a baker and his wife\',
\'And a boy named Jack who lived with his mother who had a cow named Milky White\']

For each of the four sentences, count the number of times the letter ‘e’ occurs. Put these counts into a list of four elements. The order in that list should correspond to the order of the original four sentences. (Remember to capture both upper case and lower case letters. See the “lower” function to help.) Hint: each of the four sentences is the list is string.
For each of the four sentences, count the number of words in that sentence. You can do this by splitting a sentence into words, and then counting the number of words.
Create a Numpy array (with four elements) that contains the results from part 1. Hint: create a new array using the list as the input.
Create a Numpy array (with four elements) that contains the results from part 2.
For each of the four sentences, compute the average number of occurrences of the letter “e” per word. Put the result in a four-element Numpy array. (You can use the broadcasting feature of division in Numpy.)
Finally, compute the minimum and maximum values (highest and lowest frequency) from part 5. See “min” and “max” in Numpy.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import numpy

# List containing sentences
list_of_sentences = ['Once upon a time',
                     'in a far off kingdom',
                     'lived a baker and his wife',
                     'And a boy named Jack who lived with his mother who had a cow named Milky White']
print("List of sentences:")
print(list_of_sentences)
print("")

# Array of words per sentence
words_per_sentence = []
for sentence in list_of_sentences:
    words_per_sentence.append(len(sentence.split()))
words_per_sentence = numpy.array(words_per_sentence)

print("Count of words for each sentence:")
print(words_per_sentence)
print("")

# Array of counts of e per sentence
counts_of_e_per_sentence = []
for sentence in list_of_sentences:
    counts_of_e_per_sentence.append(sentence.lower().count('e'))
counts_of_e_per_sentence = numpy.array(counts_of_e_per_sentence...

By purchasing this solution you'll be able to access the following files:
Solution.PNG and Solution.py.

50% discount

Hours
Minutes
Seconds
$20.00 $10.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats