Question: Problem Two Description and Requirements ( 3 5 pts . ) At the end of books, there usually is an index that lists the page

Problem Two Description and Requirements (35 pts.)
At the end of books, there usually is an index that lists the page numbers where a word appears in the book. In this problem, you will create an index for a text file, but instead of the page numbers you are to use line numbers.
Write the user defined Python function wordSearch(fname, wordLst) that takes the name of an e-book text file and the list of words for which you are to create the line number index.
- Requirements (\(\mathbf{20}\) points)
-(1 point) Open the text file only once.
-(1 point) Initialize an accumulator to track the line numbers.
-(3 points) Initialize dictionary with the words in wordLst and values with empty lists.
-(2 points) Set up to remove the punctuation from the text except for the apostrophe (single quote). Import the punctuation module from the string library.
- Assign \( p=\) punctuation.replace("'","') to replace the apostrophe in p with an empty string,
- And create the translation table (mapping) using str.maketrans(0)
- Use a while loop to
-(2 points) Process one line of text at a time using readline(); increment line accumulator
-(1 point) Remove punctuation from the line of text;
-(5 points) For every word in wordlist, if the word appears in the line of text, append the line number to the dictionary value list of line numbers for the key (word .
Problem Two Description and Requirements ( 3 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!