Write a function make_vocabulary (text) that takes a string text, parses it into words, and creates...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function make_vocabulary (text) that takes a string text, parses it into words, and creates a dictionary of words where keys are unique words, and their values are word occurrences. Your function should work with the following code that prints the generated dictionary. For example, if the input text is the quote from the famous English poet Lord Byron: In secret we met - In silence I grieve, That thy heart could forget, Thy spirit deceive. If I should meet thee After long years, How should I greet thee? - With silence and tears then the output of the program is: Total words in the dictionary: 27 After 1 How : 1 1:3 If : 1 In: 2 That: 1 Thy: 1 With: 1 and: 1 could: 1 deceive 1 forget 1 greet: 1 grieve: 1 heart: 1 long: 1 meet: 1 met: 1 secret : 1 should: 2 silence : 2 spirit: 1 tears: 1 thee: 2 forget 1 greet: 1 grieve 1 heart: 1 long : 1 meet met: 1 secret 1 1 should : 2 silence : 2 spirit 1 tears: 1 thee: 2 thy : 1 we: 1 years: 1 NOTE: Your program should work with the following code: #main if_name__main__': text In secret we met - In silence I grieve, That thy heart could forget, Thy spirit deceive. If I should meet thee i After long years, How should I greet thee? With silence and tears*** vocabulary - make_vocabulary(text) print('Total words in the dictionary: (len(vocabulary)}') for key in sorted(vocabulary): print(f'(key}: {vocabulary [key]}') HINTS: You may use the string method split) to parse the text into words, regular expressions to remove punctuation marks, and method get() to update the dictionary. For example, #parse text into words words text.split() #remove the punctuation marks from a word (not words!) import re word = re.sub(r'[^\w\s]", "", word) #update dictionary vocabulary [word] = vocabulary.get(word, 0) + 1 Write a function make_vocabulary (text) that takes a string text, parses it into words, and creates a dictionary of words where keys are unique words, and their values are word occurrences. Your function should work with the following code that prints the generated dictionary. For example, if the input text is the quote from the famous English poet Lord Byron: In secret we met - In silence I grieve, That thy heart could forget, Thy spirit deceive. If I should meet thee After long years, How should I greet thee? - With silence and tears then the output of the program is: Total words in the dictionary: 27 After 1 How : 1 1:3 If : 1 In: 2 That: 1 Thy: 1 With: 1 and: 1 could: 1 deceive 1 forget 1 greet: 1 grieve: 1 heart: 1 long: 1 meet: 1 met: 1 secret : 1 should: 2 silence : 2 spirit: 1 tears: 1 thee: 2 forget 1 greet: 1 grieve 1 heart: 1 long : 1 meet met: 1 secret 1 1 should : 2 silence : 2 spirit 1 tears: 1 thee: 2 thy : 1 we: 1 years: 1 NOTE: Your program should work with the following code: #main if_name__main__': text In secret we met - In silence I grieve, That thy heart could forget, Thy spirit deceive. If I should meet thee i After long years, How should I greet thee? With silence and tears*** vocabulary - make_vocabulary(text) print('Total words in the dictionary: (len(vocabulary)}') for key in sorted(vocabulary): print(f'(key}: {vocabulary [key]}') HINTS: You may use the string method split) to parse the text into words, regular expressions to remove punctuation marks, and method get() to update the dictionary. For example, #parse text into words words text.split() #remove the punctuation marks from a word (not words!) import re word = re.sub(r'[^\w\s]", "", word) #update dictionary vocabulary [word] = vocabulary.get(word, 0) + 1
Expert Answer:
Related Book For
Principles Of Information Security
ISBN: 9780357506431
7th Edition
Authors: Michael E. Whitman, Herbert J. Mattord
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Ice Cool produces two different models of air conditioners. The activities, costs, and cost drivers associated with the production processes follow. Budgeted Activity Usage 7,600 Activity Machining...
-
What is the GAAP definition of fair value?
-
An ideal regenerative Rankine cycle with an open feedwater heater is shown in Fig. 8.35. Steam leaves the boiler at 8 MPa and 600 8 C with a mass flow rate of 20 kg/s. It is extracted from the...
-
You are the financial controller of Waru Ltd, an Australian company listed on the ASX that distributes imported food products in the local market. The functional currency of Waru Ltd is A\($.\) Waru...
-
Destin Company recently acquired several businesses and recognized goodwill in each acquisition. Destin has allocated the resulting goodwill to its three reporting units: Sand Dollar, Salty Dog, and...
-
Total Energy (a) Conserved 12. Which one of the following is true in the case of inelastic collisions? Kinetic Energy Conserved Momentum Conserved (b) Conserved Not Conserved Conserved (c) Conserved...
-
A2 percent increase in the price of milk causes a 4 percent reduction in the quantity demanded of chocolate syrup. What is the cross-price elasticity of demand for chocolate syrup with respect to the...
-
Several of Jernigans accounts have fair values that differ from book value The fair values are Land 480000 Building 720000 Inventory 336000 and Liabilities 396000 Inglewood Inc acquired all of the...
-
How is the accumulated earnings credit determined?
-
George files a separate return. His wifes only source of income is $600 in interest income. Can George receive the benefit for his wife on his separate return?
-
If an expenditure is part business-related and part personal, how does the taxpayer determine the business-related amount that is deductible for tax purposes?
-
Can a sole proprietor use a fiscal tax year for a business if the individual is on a calendar tax year?
-
On what date was the Tax Reform Act of 1986 enacted, and what significance does this date have for losses derived from passive activities in 2019?
-
What does a height of 5 feet 8 inches equivalent to in meters? (1 foot = 12 inches; 1 inch = 2.54 cm; 1 meter = 100 cm.) 1.73 m 2.23 m 1.77 m 2.07 m
-
Comptech Ltd is a manufacturer of optical equipment. In September 2019, Ed Thompson the Chief Research Officer, attended a conference in Switzerland that focused on optical developments for the 21st...
-
Discuss the fact that general management, IT management, and information security management are responsible for implementing information security to protect the ability of the organization to...
-
I. Compare and contrast anomaly-based detection with signature-based detection. Explain how they are similar but uniquely different when examining intrusions into an information security system. II....
-
What is a network tool that collects copies of packets from the network and analyzes them? a. Footprint b. Router c. Network trapper d. Packet sniffer
-
If one of the physicians is randomly selected, find the probability of getting one who made a correct dosage calculation or was given the bottle with a concentration label. Dosage Calculations. Use...
-
Let R be the event of randomly selecting a senator and getting a Republican, and let D represent the event of randomly selecting a second different senator and getting a Democrat. Use words to...
-
According to the National Association for College Admissions Counseling and USA Today, 19.8% of college students take at least one class online. What is the probability of randomly selecting a...
Study smarter with the SolutionInn App