screenchot of input and output    import string pp = '''Peter Piper picked a peck of pickled peppers. A peck of pickled peppers Peter Piper picked. If Peter Piper picked a peck of pickled peppers Where's the peck of pickled peppers Peter Piper picked?''' def remove_punc(s): '''Returns a copy of string s with all punctuation removed''' #This function is already written - don't change it! for char in string.punctuation: s = s.replace(char, '') return s def count_words(text): '''Returns a dictionary with words and their counts''' pass #Create an empty dictionary #Split the text into a list of words #For each word in the list #If the word is not in the dictionary #Add it with a count of 1 #Otherwise #Add 1 to the count #Return the dictionary def show_counts(word_dict): '''Display words and their counts''' pass #Get a list of the keys from word_dict #Put the words in alphabetical order #For each word in the list #Print the word and its count def main(): '''Controls the program''' text = remove_punc(pp.lower()) #text is the name of the string with no punctuation #Use count_words to get a dictionary with words and counts #Use show_counts() to display words and counts main()

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
icon
Related questions
Question

screenchot of input and output 

 

import string

pp = '''Peter Piper picked a peck of pickled peppers.
A peck of pickled peppers Peter Piper picked.
If Peter Piper picked a peck of pickled peppers
Where's the peck of pickled peppers Peter Piper picked?'''

def remove_punc(s):
'''Returns a copy of string s with all punctuation removed'''
#This function is already written - don't change it!
for char in string.punctuation:
s = s.replace(char, '')
return s

def count_words(text):
'''Returns a dictionary with words and their counts'''
pass
#Create an empty dictionary
#Split the text into a list of words
#For each word in the list
#If the word is not in the dictionary
#Add it with a count of 1
#Otherwise
#Add 1 to the count
#Return the dictionary

def show_counts(word_dict):
'''Display words and their counts'''
pass
#Get a list of the keys from word_dict
#Put the words in alphabetical order
#For each word in the list
#Print the word and its count

def main():
'''Controls the program'''
text = remove_punc(pp.lower()) #text is the name of the string with no punctuation
#Use count_words to get a dictionary with words and counts
#Use show_counts() to display words and counts

main()

2. Use a dictionary to count the number of occurrences of each word in some text and display the
words and their counts in alphabetical order. Make the text lower case (already done for you). Do
not display any word that does not occur in the text. Use pp for the text - but your program should
still work if pp is changed.
Save & Run
Load History
1 import string
2
3 pp = ''Peter Piper picked a peck of pickled peppers.
4 A peck of pickled peppers Peter Piper picked.
5 If Peter Piper picked a peck of pickled peppers
6 Where's the peck of pickled peppers Peter Piper picked?'''
7
8 def remove_punc (s) :
'''Returns a copy of string s with all punctuation removed''"
#This function is already written - don't change it!
for char in string.punctuation:
= = s.replace (char, '')
10
11
12
13
return s
14
15 def count_words (text) :
16
'''Returns a dictionary with words and their counts'''
17
pass
18
#Create an empty dictionary
#Split the text into a list of words
#For each word in the list
19
20
21
#If the word is not in the dictionary
22
#Add it with a count of 1
23
#Otherwise
24
#Add 1 to the count
25
#Return the dictionary
Transcribed Image Text:2. Use a dictionary to count the number of occurrences of each word in some text and display the words and their counts in alphabetical order. Make the text lower case (already done for you). Do not display any word that does not occur in the text. Use pp for the text - but your program should still work if pp is changed. Save & Run Load History 1 import string 2 3 pp = ''Peter Piper picked a peck of pickled peppers. 4 A peck of pickled peppers Peter Piper picked. 5 If Peter Piper picked a peck of pickled peppers 6 Where's the peck of pickled peppers Peter Piper picked?''' 7 8 def remove_punc (s) : '''Returns a copy of string s with all punctuation removed''" #This function is already written - don't change it! for char in string.punctuation: = = s.replace (char, '') 10 11 12 13 return s 14 15 def count_words (text) : 16 '''Returns a dictionary with words and their counts''' 17 pass 18 #Create an empty dictionary #Split the text into a list of words #For each word in the list 19 20 21 #If the word is not in the dictionary 22 #Add it with a count of 1 23 #Otherwise 24 #Add 1 to the count 25 #Return the dictionary
26
27 def show_counts (word_dict) :
28
'''Display words and their counts'''
29
pass
#Get a list of the keys from word dict
30
31
#Put the words in alphabetical order
32
#For each word in the list
33
#Print the word and its count
34
35 def main ():
36
'''Controls the program'''
text = remove_punc (pp.lower ()) #text is the name of the string
#Use count_words to get a dictionary with words and counts
#Use show_counts () to display words and counts
37
38
39
40
41 main ()
42
Transcribed Image Text:26 27 def show_counts (word_dict) : 28 '''Display words and their counts''' 29 pass #Get a list of the keys from word dict 30 31 #Put the words in alphabetical order 32 #For each word in the list 33 #Print the word and its count 34 35 def main (): 36 '''Controls the program''' text = remove_punc (pp.lower ()) #text is the name of the string #Use count_words to get a dictionary with words and counts #Use show_counts () to display words and counts 37 38 39 40 41 main () 42
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Types of Function
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education