subject

1. Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following: A. How to format each dictionary item as a text string in the input file.
B. How to covert each input string into a dictionary item.
C. How to format each item of your inverted dictionary as a text string in the output file.
D. Create an input file with your original three-or-more items and add at least three new items, for a total of at least six items.
2. Copy your program from Part 1 and modify it to do the following:
A. Read the output file from Part 1 and create a dictionary from it (the inverted dictionary from Part 1).
B. Invert that dictionary.
C. Write the re-inverted dictionary to an output file.
D. It will be interesting to see if your original dictionary is reversible. If you invert it twice, do you get the original dictionary back?
Include the following in your Learning Journal submission:
The input file for your original dictionary (with at least six items).
The Python program for Part 1.
The output file for your inverted dictionary, which is also the input file for Part 2.
The Python program for Part 2.
The output file for your twice-inverted dictionary.
A description of any differences between your program for Part 1 and your program for Part 2.
A description of any differences between the original input file and the final twice-inverted output file.
(This was the code from Learning Journal from Unit 7 & it's Output)
def invert_dict(d):
inverse = dict()
for key in d:
values = d[key]
for value in values:
if value not in inverse:
inverse[value] = [key]
else:
inverse[value].append(key)
return inverse
d = {
"k1": ["v1", "v2"],
"k2": ["v3", "v2"],
"k3": ["v4", "v7"]
}
print("Original dictionary: " + str(d))
print("Inverted dictionary: " + str(invert_dict(d)))

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 22:00
What is a distinguishing feature of today’s graphic application software?) graphic applications are used today on a variety of devices, including touch-screen kiosks and mobile phones.
Answers: 3
question
Computers and Technology, 24.06.2019 00:40
What social factors affect your health
Answers: 3
question
Computers and Technology, 24.06.2019 07:30
John recently worked on a project about various programming languages. he learned that though procedural language programs are useful, they have disadvantages too. what is a disadvantage of programs written in procedural languages? a. programs do not represent data complexity. b. programs take more time to execute. c. programs are prone to security threats. d. programs do not interface with multiple platforms.
Answers: 3
question
Computers and Technology, 24.06.2019 16:30
Pressing the backspace key deletes the text to the of the insertion point. the left or the right?
Answers: 1
You know the right answer?
1. Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write t...
Questions
question
Spanish, 27.05.2021 01:00
question
Mathematics, 27.05.2021 01:00
question
French, 27.05.2021 01:00
question
Mathematics, 27.05.2021 01:00
question
Mathematics, 27.05.2021 01:00
question
Mathematics, 27.05.2021 01:00
Questions on the website: 13722362