Question: Question 1: Write a function called longest_word_length , which takes a string as input and returns a number giving the length (number of characters) in

Question 1:

Write a function called longest_word_length, which takes a string as input and returns a number giving the length (number of characters) in the longest single word in the string. For example , calling the function with the code below:

longest_word_length("This is a sentence")

returns the value 8 because "sentence" is the longest word.

Question 2

Write a function called word_freq that accepts a string parameter str and uses a dictionary accumulation pattern to return a dictionary with the frequency of words in the str. For example, running the code below:

s = 'it is what it is and only what it is' print(word_freq(s))

Displays the output below:

{'it': 3, 'is': 3, 'what': 2, 'and': 1, 'only': 1}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!