Ask Question
29 December, 09: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.

+3
Answers (1)
  1. 29 December, 11:21
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers