Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Im very confused on how separate strings In the following cell, we give two strings. You can assume that strings have no punctuation or new

Im very confused on how separate strings

In the following cell, we give two strings. You can assume that strings have no punctuation or new lines. For all of the strings, we would like for you to save the words in each string in a separate list.

In [ ]:

# We have given you four strings. These strings are taken from classic novels # posted here: # https://oxfordsummercourses.com/articles/books-for-english-literature-students-to-read/ # You can alter them or add more or use user input also. # The format given is for multi-line strings using three quotation marks before and after. fitzgerald_quote = """in my younger and more vulnerable years my father gave me some advice that Ive been turning over in my mind ever since whenever you feel like criticizing any one he told me just remember that all the people in this world havent had the advantages that youve had""" dickens_quote = """suffering has been stronger than all other teaching and has taught me to understand what your heart used to be I have been bent and broken but I hope into a better shape""" lee_quote = """you never really understand a person until you consider things from his point of view until you climb inside of his skin and walk around in it""" austen_quote = """nobody who has not been in the interior of a family can say what the difficulties of any individual of that family may be""" # TODO: Edit the 4 lines of code to save the words from each quote to use for the rest # of the lab. Be sure to save the words for each quote in a list of strings. fitzgerald_words = [] dickens_words = [] lee_words = [] austen_words = [] # Our test code is below. Do not modify it. assert(len(fitzgerald_words) == 49) assert(len(dickens_words) == 33) assert(len(lee_words) == 27) assert(len(austen_words) == 24) 

Getting the frequency of words

In the following cell complete the function frequency that, given a list of words, returns a dictionary with the frequency count for each word in the list of words.

In [ ]:

# TODO: frequency is given a list of words # and returns a dictionary of the counts of each # word in the list of words def frequency(words): # Empty dictionary that will be filled and returned word_counts = {} # TODO: Loop through each word in the words list # if the word is in the dictionary, increment its count # otherwise, add the word to the dictionary and set its # count to 1 return word_counts # Call the frequency function to get the word counts dictionary # for each quote above fitzgerald_counts = frequency(fitzgerald_words) dickens_counts = frequency(dickens_words) # TODO: Call the frequency function to get the word counts for the Lee # and Austen quotes lee_counts = {} austen_counts = {} assert(len(fitzgerald_counts) == 40) assert(len(dickens_counts) == 28) assert(len(lee_counts) == 22) assert(len(austen_counts) == 20) assert(fitzgerald_counts['my'] == 3) assert(dickens_counts['and'] == 2) assert(lee_counts['you'] == 3) assert(austen_counts['a'] == 1) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What do you think of the MBO program developed by Drucker?

Answered: 1 week ago