Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

2. Be a good example:

Answered: 1 week ago