Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. Include the

Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file.

Include the following in your Learning Journal submission:

The input file for your original dictionary (with at least six items).

The Python program to read from a file, invert the dictionary, and write to a different file.

The output file for your inverted dictionary.

The code and its output must be explained technically. The explanation can be provided before or after the code, or in the form of comments within the code. For code modification type of questions, always mention or clearly highlight the part which is modified, along with the reason stated, as a code comment. The descriptive part of your response must be at least 200 words.

THIS IS THE INPUT OF THE CODE THAT I USED.

image text in transcribed

image text in transcribed

THIS IS THE OUTPUT OF THE GIVEN CODE ABOVE.

image text in transcribed

PLEASE INCLUDE A DETAILED EXPLANATION OF THE PROCEDURE.

THANK YOU.

| Some information about 5 students is given in a dictionary named, Nevermorel \# Student ID, Year of Birth, and grades are given in the dictionary \( \begin{array}{lc}37 & \text { print(students) } \\ 38 & \\ 39 & \text { \# Modified invert_dict function } \\ 40 & \text { def invert_dict(d) : } \\ 41 & \text { inverse = dict() } \\ 42 & \text { for key in d: } \\ 43 & \text { val = d[key] } \\ 44 & \text { for list_item in val: } \\ 45 & \text { if list_item not in inverse: } \\ 46 & \text { inverse[list_item] = [key] } \\ 47 & \text { else: } \\ 48 & \text { inverse[list_item] } \text {.append(key) } \\ 49 & \text { return inverse } \\ 50 & \text { \# Print the inverted dictionary } \\ 51 & \text { my_invert = invert_dict(students) } \\ 52 & \text { print("The inverted dictionary") } \\ 53 & \text { print(my_invert) }\end{array} \) The original dictionary \{'Dhenise' : ['107557', 1999, '88' ], 'Lindon' : ['107558', 1998, '85'], 'Chong' : ['107559', 1998, '89'], 'Majoe' : ['107560', 1996, '90'], 'Eric' : ['107561', 1997, '95']\} The inverted dictionary None The original dictionary \{'Dhenise' : ['107557', 1999, '88'], 'Lindon' : ['107558', 1998, '85'], 'Chong' : ['107559', 1998, '89'], 'Majoe' : ['107560' , 1996, '90' ], 'Eric': ['107561', 1997, '95']\} The inverted dictionary \{'107557' : ['Dhenise' ], 1999: ['Dhenise' ], '88' : ['Dhenise' ], '107558' : ['Lindon' ], 1998: ['Lindon', 'Chong' ], '85': ['Lindon' ], '107559' : ['Chong' ]\}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions