screenshot 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?''' stopwords = "a,an,any,can,if,is,it,it's,nor,not,of,on,nor,the" 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, stopwords): '''Returns a dictionary with words and their counts''' pass #Create an empty dictionary #Split the text into a list of words (split on whitespace) #Split the stopwords into another list of words (split on comma) #For each word in the list #If the word is not in the stop 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; send it text and stopwords #Use show_counts() to display words and counts main()

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

screenshot 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?'''

stopwords = "a,an,any,can,if,is,it,it's,nor,not,of,on,nor,the"

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, stopwords):
'''Returns a dictionary with words and their counts'''
pass
#Create an empty dictionary
#Split the text into a list of words (split on whitespace)
#Split the stopwords into another list of words (split on comma)
#For each word in the list
#If the word is not in the stop 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; send it text and stopwords
#Use show_counts() to display words and counts

main()

#If the word is not in the stop list
#If the word is not in the dictionary
24
25
26
#Add it with a count of 1
27
#Otherwise
28
#Add 1 to the count
29
#Return the dictionary
30
31 def show_counts (word_dict) :
32
'''Display words and their counts'''
33
pass
34
#Get a list of the keys from word_dict
35
#Put the words in alphabetical order
36
#For each word in the list
37
#Print the word and its count
38
39 def main () :
40
'''Controls the program'''
41
text = remove_punc (pp.lower ())
ttext is the name of the string
42
#Use count_words to get a dictionary with words and counts; sen
43
#Use show_counts () to display words and counts
44
45 main ()
46
Transcribed Image Text:#If the word is not in the stop list #If the word is not in the dictionary 24 25 26 #Add it with a count of 1 27 #Otherwise 28 #Add 1 to the count 29 #Return the dictionary 30 31 def show_counts (word_dict) : 32 '''Display words and their counts''' 33 pass 34 #Get a list of the keys from word_dict 35 #Put the words in alphabetical order 36 #For each word in the list 37 #Print the word and its count 38 39 def main () : 40 '''Controls the program''' 41 text = remove_punc (pp.lower ()) ttext is the name of the string 42 #Use count_words to get a dictionary with words and counts; sen 43 #Use show_counts () to display words and counts 44 45 main () 46
3. Often, when dealing with text, we want to ignore certain words. For example, when searching for
text we probably don't want to include words like a, the, of, and so forth. These words are called
'stopwords' and are usually kept in a file. Write a program to count the number of occurrences of
words in some text but skip the stopwords. Again, use a dictionary to count the occurrences then
display the words (in alphabetical order) and their counts. Use the text in the variable pp - but your
program should work for any text; the stopwords are stored in the variable stopwords. Note that the
stopwords are separated by comma - not space.
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 stopwords = "a, an, any, can, if, is, it,it's,nor, not, of, on, nor, the"
10 def remove_punc (s):
11
'''Returns a copy of string s with all punctuation removed'''
12
#This function is already written - don't change it!
13
for char in string.punctuation:
14
= = s.replace (char, '')
15
return S
16
17 def count_words (text, stopwords) :
18
'''Returns a dictionary with words and their counts'''
19
pass
20
#Create an empty dictionary
#Split the text into a list of words (split on whitespace)
#Split the stopwords into another list of words (split on comma
#For each word in the list
21
22
23
Transcribed Image Text:3. Often, when dealing with text, we want to ignore certain words. For example, when searching for text we probably don't want to include words like a, the, of, and so forth. These words are called 'stopwords' and are usually kept in a file. Write a program to count the number of occurrences of words in some text but skip the stopwords. Again, use a dictionary to count the occurrences then display the words (in alphabetical order) and their counts. Use the text in the variable pp - but your program should work for any text; the stopwords are stored in the variable stopwords. Note that the stopwords are separated by comma - not space. 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 stopwords = "a, an, any, can, if, is, it,it's,nor, not, of, on, nor, the" 10 def remove_punc (s): 11 '''Returns a copy of string s with all punctuation removed''' 12 #This function is already written - don't change it! 13 for char in string.punctuation: 14 = = s.replace (char, '') 15 return S 16 17 def count_words (text, stopwords) : 18 '''Returns a dictionary with words and their counts''' 19 pass 20 #Create an empty dictionary #Split the text into a list of words (split on whitespace) #Split the stopwords into another list of words (split on comma #For each word in the list 21 22 23
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY