Question: Using Python Write: A function called line occurrences that takes one parameter, filename, the name of an input file. You may assume the file is

Using Python  Using Python Write: A function called line occurrences that takes one

Write: A function called line occurrences that takes one parameter, filename, the name of an input file. You may assume the file is in the current working directory of the program. line occurrences should return a dictionary, where each key is a word in the input file, and its value is a list of integers representing the line numbers where the word occurs in the file. Line numbers should be 0-indexed. Additional requirements: . If a word appears multiple times on a line, its line number may appear more than once in the value list. . Wordsshouldbecountedcase-insensitiveandhavetheirleadingandfollowingpunctuation removed. For instance, Repetition, and repetition in the example below should be considered as the same word. Example: The following is the content of a file called poem.txt: Repetition, repetition is the way Bob learns Repeating consciously until he discern Running lin.e.essurrenss poem.txt) should return: learns [o), 'until: [1l, "he: [1], 'the: [O], discern [11. 1s:[ol, 'way: [ol. repeating[1. bob: [ol, 'repetition: to, 0],. 'consciously: [1]) Of course, dictionary keys are unordered, so your results may appear in a different order on the screen when printed

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 Databases Questions!