Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please help me code this for python?! Def store (d, filename): Given a dictionary d and a string filename, create a new file

image text in transcribed

Can you please help me code this for python?!

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 asciibetically by their keys. See the example below. Assumptions: (1) if a file named filename already exists, then the content out.txt 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:\t1, \t3 n'' 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 before after 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 3 non-empty file can contain one or more lines ending with a newline; (4) each line contains a single integer and nothing else, 9 and (5) the function returns None. Examples: append_total("f1.txt") corresponds to the files to the right

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_2

Step: 3

blur-text-image_3

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

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago