Ask Question
26 February, 21:06

In python:

Given a dictionary d, create a new dictionary that reverses the keys and values of d. Thus, the keys of d become the values of the new dictionary and the values of d become the keys of the new dictionary. You may assume d contains no duplicate values (that is, no two keys map to the same values.) Associate the new dictionary with the variable inverse.

+5
Answers (1)
  1. 27 February, 00:36
    0
    Following are the program in the Python Programming Language:

    #set dictionary

    d = { 'State' : 'Delhi', 'Country' : 'India'};

    #reverse the dictionary.

    revers = dict ((v, k) for k, v in d. items ())

    #Displays the reversed dictionary.

    print ("Dictionary is: / n")

    print (revers)

    Output:

    Dictionary is:

    {'Delhi': 'State', 'India': 'Country'}

    Explanation:

    Here, we set the dictionary data type variable "d" then, we set the variable in which we store the reverse of the dictionary in which key is converted into the value and value is converted into the key. and finally we print the reverse dictionary.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “In python: Given a dictionary d, create a new dictionary that reverses the keys and values of d. Thus, the keys of d become the values of ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers