Home / Questions / Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the
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:
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.
Include the following in your Learning Journal submission:
Here is my code:
def invert_dict(d):
inverse = dict()
for key in d:
val = d[key]
for item in val:
inverse[item]=key;
return inverse
#hist is creating a dictionary to identify the list of animal families and its type.
hist = dict({'Herbi': {'cow', 'horse', 'rabbit'},
'Carnivore': {'lion', 'tiger', 'chetha'},
'Reptiles': {'russel viper', 'python', 'black mamba'}
})
print("Before the inversion")
for key in hist:
print(key,hist[key], sep=" : ")
inverse = invert_dict(hist)
print("nAfter the inversion")
for key in inverse:
print(key,inverse[key], sep=" : ")
==
Output:
Before the inversion
Herbi : {'rabbit', 'horse', 'cow'}
Carnivore : {'chetha', 'tiger', 'lion'}
Reptiles : {'python', 'black mamba', 'russel viper'}
After the inversion
python : Reptiles
black mamba : Reptiles
russel viper : Reptiles
We identify the list of animals according to their kind. Also inverted dictionary is helpful to identify whether the particular is herbivore, carnivore or reptile family. But here this seems the inverted dictionary is not very helpful because it consumes more memory.
The required answer is bold.. What I need for the answer is above unbolded texts.
Apr 02 2020 View more View Less
Keystone Steel Company has two departments, Casting and Rolling. In the Rolling Department, ingots from the Casting Department are rolled into steel sheet. The Rolling De...
May 11 2021Write electronic configurations for the following ions?Ni2+Cd2+Zr3+ and Zr4+Os2+ and Os3+
Jun 29 2021President Franklin D. Roosevelt in an attempt to end the economic devastation which occurred during the great depression introduced a set of legislations known as:a) The ...
Jul 07 2021Write-Off of Uncollectible AccountsThe Rock has credit sales of $540,000 during 2019 and estimates at the end of 2019 that 2% of these credit sales will eventually defaul...
Jun 25 20211. The 2011 balance sheet of Anna’s Tennis Shop, Inc,. showed long-term debt of $1.45 million, and the 2012 balance sheet showed long-term debt of $1.52 million. The 2012...
Apr 09 2020A manufacturing company is planning a $600 000 expansion 6 years from now. By that time the company intends to accumulate 75% of the cost of the expansion by making payme...
Aug 23 2020Finding a General Rule In Exercises 69 and 70, use a computer algebra system to find theintegrals for n = 0, 1, 2,and 3. Use the result to obtain a general rule for the i...
Aug 18 2021In the short run, a firm incurs fixed costsa. only if it incurs variable costs.b. only if it produces no output.c. only if it produces a positive quantity of output.d. wh...
Apr 28 2021Project Q has an initial cost of $257,412 and projected cashflows of $123,300 in Year 1 and $180,300 in Year 2. Project R hasan initial cost of $345,000 and projected cas...
Apr 10 2020he most recent financial statements for Hornick, Inc., are shown here (assuming no income taxes):Income StatementBalance SheetSales8,500Assets19,500Debt6,200Costs6,000Equ...
Aug 22 2020