
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
screenshot of input and output
import string
def readfile(fname):
pass
#Open the file for reading
#Read the contents as one long string
#Close the file
#Remove the punctuation
#Return the lower-case contents
def main():
filename = "gb.txt"
#Use readfile() to get the text
#Create an empty list to hold the unique words
#Split the text into a list of words (split on whitespace)
#For each word in the list of words
#If the word is not in the unique word list
#Add it (append it to the unique word list)
#Print the number of unique words
#Print the unique words
main()

Transcribed Image Text:4. Write a program that counts the number of unique words in a text file; use gb.txt as a test file - but
your program should work for any file if the filename is changed. Write a function readfile() that
reads the file, removes punctuation, and returns the contents as a lower case string. In main, count
the number of unique words and print that number and the words that only occur one time.
Save & Run
Load History
Show CodeLens
1 import string
2
3 def readfile (fname) :
4
pass
#Open the file for reading
6
#Read the contents as one long string
7
#Close the file
#Remove the punctuation
#Return the lower-case contents
10
11 def main ():
12
filename = "gb.txt"
13
#Use readfile () to get the text
14
#Create an empty list to hold the unique words
#Split the text into a list of words (split on whitespace)
#For each word in the list of words
15
16
17
#If the word is not in the unique word list
18
#Add it (append it to the unique word list)
19
#Print the number of unique words
20
#Print the unique words
21
22 main ()
23
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
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
- LLNode head, curr; Write the statements to build the following list. head "rose" "lilac" "orchid" 1.arrow_forwardAfter a tuple is created, its items can be changed. True False A tuple's items can be access by square brackets, similar to lists. True Falsearrow_forwardLab Goal : This lab was designed to teach you more about list processing and algorithms.Lab Description : Write a program that will search a list to find the first odd number. If an odd number is found, then find the first even number following the odd number. Return the distance between the first odd number and the LAST even number. Return -1 if no odd numbers are found or there are no even numbers following an odd numberarrow_forward
- # cannot contain syntax error def replace(keyv:int,newv:int,S:set)->set:"Find a number keyv from a given set S" # note S is a set"As soon as found, replace the number keyv with a number newv""return the resultant set with the other numbers unchanged""Input keyv to be found, if found replace with newv else no change to the set""S contains a set of int, output the resultant set" if __name__ == "__main__":# testing cod goes inside this ifarrow_forwardA list called parts has already been created and filled with data. It has a length of 5. Write a for loop that prints each value in this list.arrow_forwardWrite a statement, using pyhton language, that creates a two-dimensional list with 5 rows and 3 columns. Then write nested loops that get an integer value from the user for each element in the list.arrow_forward
- POEM List[POEM_LINE] PRONUNCIATION_DICT Dict[str, PHONEMES] Do not add statements that call print, input, or open, or use an import statement. Do not use any break or continue statements.arrow_forwardC++ Add a search command that asks the user for a string and finds the first line that contains that string. The search starts at the first line currently displayed and stops at the end of the file. If the string is found, the line that contains it is displayed at the top. In case the user enters a string X that does not occur in the file, the program should print the error message: ERROR: string "X" was not found. Attached is the first lines of the .txt filearrow_forwardIn NumPy write a program to generate a list that contain 5 random integers in the range 1 to 100. Display the list in the output.arrow_forward
- python help, please show all steps and include comments Write a function largerLst() that takes a list of numbers (i.e., int or float values) as a parameter and returns a new list constructed out of it. The list returned has all the values in the parameter list that are larger than the element immediately to their right, that is, larger than their right neighbor. If the parameter list is empty or there are no values larger than their right neighbor, then the function returns an empty list. Note that the last element in the list will never be included in the list returned since it does not have a right neighbor. The function should not change the parameter list in any way. Note that a correct solution to this problem must use an indexed loop That is, one that makes a call to the range() function to generate indices into the list which are used to solve the problem (Review lecture notes 8-1). A solution that does not use an indexed loop will not be accepted. Note in particular that you…arrow_forwardC++ Add a search command that asks the user for a string and finds the first line that contains that string. The search starts at the first line currently displayed and stops at the end of the file. If the string is found, the line that contains it is displayed at the top. In case the user enters a string X that does not occur in the file, the program should print the error message: ERROR: string "X" was not found.arrow_forwardLottery number generator: Write a program that generates aseven-digit lottery number. The program should have a loopto generate seven random numbers, each in the range 0through 9 and assign each number to a list element.2. Write another loop to display the contents of the list.3. Tip: You will need to create/initialize your list before you canassign numbers to it.4. Use program 7-1 sales_list as an example. You will start witha seven-digit lottery number that contains all zeros. Then inyour loop, you will assign a random number instead ofgetting the data from the user.Turn in your program to the practice assignment link in coursecontent.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education