1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
svetoff [14.1K]
3 years ago
11

Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a fil

e. You will need to decide on the following: 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. 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.
Computers and Technology
1 answer:
Bond [772]3 years ago
6 0

Answer:

Following are the code to this question:

import ast as a #import package ast

d1= {}#defining an empty dictionary  

def invert_dictionary(d1):#defining a method invert_dictionary

   i = dict()#defining variable i that hold dict method  

   for k in d1:#defining for loo to check dictionary value

       val = d1[k]#defining val variable to holds dictionary key values

       for val1 in val:#defining another for loop to hold value of dictionary and inverse it

           if val1 not in i:#defining if block to check value

               i[val1] = [k]#hold key value

           else:#defining else block

               i[val1].append(k)#add value in dictionary

   return i#return inverse value

with open("dict_items.txt", "r") as data:#use open method to add a list as a file

   dict_item = a.literal_eval(data.read())#defining a variable that covert item as a text string in the input file  

   '''covert input string into dictionary item'''

   e_val = input("Please enter a value")#defining variable e_val to input value

   dict_item['4']=str(e_val)#holding value in dictionary

   dict_item['5']='e'#holding value in dictionary

   dict_item['6']='f'#holding value in dictionary

   '''Invert the dictionary value '''

   invert_data =invert_dictionary(dict_item)#defining variable to holding method value

'''calculating the format of each item of inverted dictionary as a text string output file.'''

f_data = {i:str(j[0]) for i,j in inverted_data.items() }#defining f_data to hold coverted value

import json as j#import package

with open('out_put.txt', 'w') as file:#use open method to open file

   file.write(j.dumps(f_data))#add value

Explanation:

In the above-given code has four parts which can be defined as follows:

In the first part, a method invert_dictionary is defined that accepts a dictionary, and defines two for loops in which the second loop uses a conditional statement to convert the inverse form and return its value, and after inverse it use the open method to add a list as a file, and defining a variable that covert item as a text string in the input file.

In the second step, a variable e_val is declared for input value , and use the dict_item variable to holding dictionary  value, and call the method and hold its value.

In the third and fourth step it calculating the format of each item of inverted dictionary as a text string output file.

You might be interested in
How does the variance as a measure of the dispersion of a data set relate to the measure of central tendency (i.e. mean)? What c
love history [14]

Answer: Variance is a measure of dispersion of data points from the mean. Low variance indicates that data points are generally similar and do not vary widely from the mean. High variance indicates that data values have greater variability and are more widely dispersed from the mean.

Explanation:

Yw and pls mark me as brainiest

7 0
3 years ago
What is a search engine and how is it different from a browser?
padilas [110]
A search engine is a tab where you can input keywords to find certain data in the internet. An example of a search engine would be Google or Yahoo. If you type in google "images of a turtle," it would search the entire internet for an image of a turtle then send it to you. Search engines are different than browsers because browsers are the tool to open up google aka the search engine itself, then you can proceed to search up what you want.

Please give brainliest! Thank you! :D 
6 0
3 years ago
Where does most of the work in creating a presentation will take place? Either formatting toolbar, normal (Slide) view, slide so
LUCKY_DIMON [66]
The normal (slide) view 
8 0
4 years ago
Read 2 more answers
Name this<br><br>The feature allows you to add text/picture in the background of the document. ​
sertanlavr [38]
I think it is picture/text wrapping

I wouldn’t trust this though

I’m sorry if it’s wrong
4 0
3 years ago
In order to create a horizontal 2-inch-thick dotted green line exactly 2 inches away from the top of the canvas, a graphic artis
Harrizon [31]

Answer:

I Think meter .

Explanation:

Not so Sure

4 0
3 years ago
Read 2 more answers
Other questions:
  • Give a big-O estimate for the number of comparisons used by the algorithm that determines the number of 1s in a bit string of le
    9·2 answers
  • You want to discard your old computer and want to securely erase the data from your hard drive. What can you use to do this and
    10·1 answer
  • Analyze the following network traffic logs depicting communications between Computer1 and Computer2 on opposite sides of a route
    12·1 answer
  • Technological progress has reduced the cost of manufacturing mp3 players. what happens if demand is unchanged?
    9·1 answer
  • Your task is to improve a multi-threaded program that frequently writes small entries to a shared file by introducing a layer th
    7·1 answer
  • Write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing. Ask
    9·1 answer
  • Your one output statement should occupy two lines in your program
    13·1 answer
  • Which of the following statements is FALSE?
    5·1 answer
  • What do you believe the year 2058 will be like? Reply with a link or a picture along with an explanation why. There should be a
    14·1 answer
  • Consumers affect which goods and services are produced because they _____.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!