Question
Please help me with this question Finding Unique Words in a File In this exercise you will read the words contained in a file and
Please help me with this question
Finding Unique Words in a File In this exercise you will read the words contained in a file and process them. Your program must create a list of the unique words found in the file (ignoring case). Words are only composed of alphabetic characters; digits and punctuation should be removed. Write a fruitful function named open_file() that prompts the user for a file name. The function then attempts to open the file for reading. When it is successful it returns the file handle. If the named file is not readable then the function displays a message and prompts for another file name. Use the os.path.isfile() function to check to see if the file exists. Do not use exception handling in this program. Write a main driver that uses open_file() to get a file handle for the file that the user requests. Then reads the file extracting all the words ignoring punctuation and non-alphabetic characters. Either during the reading process or after the entire file has been read (your choice) create a list containing the unique words. Change all words to lowercase before you process them. Then display a list of these words sorted in alphabetic order. As one of the tests for your final submission you should use the text of Robert Frosts Fire and Ice which is contained in FireAndIce.txt. You also should use Leunigs How To Get There contained in GettingThere.txt.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started