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 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 wordSearchfname wordLst that takes the name of an ebook text file and the list of words for which you are to create the line number index.
Requirements mathbf points
point Open the text file only once.
point Initialize an accumulator to track the line numbers.
points Initialize dictionary with the words in wordLst and values with empty lists.
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 strmaketrans
Use a while loop to
points Process one line of text at a time using readline; increment line accumulator
point Remove punctuation from the line of text;
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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
