Question: Python 3 Function Coding: I need help coding these three functions. Any help is appreciated! Def locate(filename, s): Given a string filename and a string
Python 3 Function Coding:
I need help coding these three functions. Any help is appreciated!

Def locate(filename, s): Given a string filename and a string s to search for in the file, return an ordered list of all line numbers corresponding to the lines containing at least one occurrence of the string s (case sensitive). Assumptions: (1) file indicated by filename exists in the current directory; (2) file can be empty; (3) line number starts with 1; and (4) s is a non-empty string that does not span more than a single line. Examples given the file to the right: locate ("in.txt", "up") rightarrow [1, 3] hill Will Will went up hill locate ("in.txt", "ill") rightarrow [1, 2, 3] Will hill still locate ("in.txt", "will") rightarrow [] Will is up hill still def store(d, filename): Given a dictionary d and a string filename, create a new file named filename and output the content of d into that file. You can assume that the dictionary d always has the key: value format as string:[list, of, integers]. Every key-value pair of the dictionary should be output as: a string that starts with key, followed by ":", a tab, then the integers from the value list Every integer should be followed by a " and a tab except for the very last one, which should be followed by a newline. Multiple items of the dictionary must be sorted acidimetrically by their keys. See the example below. Assumptions: (1) if a file named filename already exists, then the content should be overwritten; (2) dictionary d could be empty; (3) the value list could be empty; and (4) the function returns None. Examples: d = {'orange':[1, 3], 'apple':[2]} store(d, "out .txt") should end up with a file to the right # the file contents should be read as this string: # "apple:\t2 orange:\tl, \t3 " def append_total(filename): Given a string filename of a file containing one integers (one per line), calculate the total of all the integers and append the line "Total:" followed immediately by the integer total (no spaces in between) and ending with a newline. See example. Assumptions: (1) file indicated by filename exists in the current directory; (2) file can be empty, and if so the sum will be 0; (3) a non-empty file can contain one or more lines ending with a newline; (4) each line contains a single integer and nothing else, and (5) the function returns None. Examples: append_total("fl.txt") corresponds to the files to the right
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
