Computers and Technology

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)))

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 20:50, solo4360
What does operator overloading allow you to do?
Answers: 2
image
Computers and Technology, 23.06.2019 14:30, rose6038
Select the correct answer. peter has launched a website that features baby products. however, clients often find they are unable to access the website because the server is down. which feature of cybersecurity should peter focus on for his website? a. data authenticity b. data privacy c. data availability d. data integrity e. data encryption
Answers: 3
image
Computers and Technology, 24.06.2019 02:10, trint5952
Aspeed limit sign that says "night" indicates the legal speed between sunset and sunrise.
Answers: 2
image
Computers and Technology, 24.06.2019 18:20, 12375819
Use a while-end loop in a script file to calculate the sum of the first n terms of the series: summation sign on the top n bottom k=1 : )^k * k^2 +5k)/3^k show the script file and the two results of n = 10 and n = 20.
Answers: 2
Do you know the correct answer?
1. Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write t...

Questions in other subjects:

Konu
Mathematics, 15.12.2020 20:30
Konu
Spanish, 15.12.2020 20:30
Konu
Mathematics, 15.12.2020 20:30