Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In python Write a function that takes a filename and a target string as input pa

ID: 3843072 • Letter: I

Question

In python

Write a function that takes a filename and a target string as input parameters and returns a list of the lines in the file that contain the target string. The function uses the filename to open the file, loops through the lines of the file and saves each line that contains the target string as one element of the list. No printing should be done inside the function - it should just return the list of lines that contain the target string. The function must have the following signature:

It would be used as follows:

Don't worry about printing the extra newline characters that are part of each line. Of course, if that bothers you then you can get rid of the extra lines in more than one way. Let's say a line of the file is stored in a string called line, then any of the following would print just one of the two newline characters:

Explanation / Answer

import re

if m is None:

else

my_list.append(row)

2)

def printFileMatches(filename, target):

my_list = getFileMatches(filename, target)

print(my_list)

return

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote