Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Modify your this program to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on
Modify your this program to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following:
def invert_dict(d): inverse = dict() for key in d: val = d[key] if val not in inverse: inverse[val] = [key] else: inverse[val].append(key) return inverse
- How to format each dictionary item as a text string in the input file.
- How to covert each input string into a dictionary item.
- How to format each item of your inverted dictionary as a text string in the output 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.
- A description of how you chose to encode the original dictionary and the inverted dictionary in text files
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started