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 07:20
Write a pseudocode solution for each of these problems. 1. design a while loop that lets that user enter a number. the number should be multiplied by 10, and the result stored in a variable named product. the loop should iterate as long as product contains a value less than 100. 2. design a do-while loop that asks the user to enter two numbers. the numbers should be added and the sum displayed. the loop should ask the user whether he or she wishes to perform the operation again. if so, the loop should repeat; otherwise it should terminate. 3. design a for loop that displays the following set of numbers: 0, 10, 20, 30, 40, 50 100. 4. design a nested loop that displays 10 rows of # characters. there should be 15 # characters in each row. 5. convert this for loop to a while loop. declare integer count for count = 1 to 50 display count end for 6. find the error in the following pseudocode. declare boolean finished = false declare integer value, cube while not finished display “enter a value to be cubed.” input value; set cube = value ^ 3 display value, “ cubed is “, cube end while
Answers: 2
question
Computers and Technology, 22.06.2019 10:30
You have a large, late-model pick-up truck with a rear seat. the pick-up truck weighs 6,500 pounds. the florida seat belt law
Answers: 1
question
Computers and Technology, 22.06.2019 11:00
Which law requires employers to provide safe working environments for their employees? a. civil rights act b. fair labor standards act c. occupational safety and health act d. wagner act
Answers: 1
question
Computers and Technology, 22.06.2019 18:00
What is the first view you place in your drawing?
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
Mathematics, 22.06.2019 03:50
Questions on the website: 13722367