Programming Examples
Python program to Create a dictionary with the opposite mapping
Given the dictionary x = {‘k1’: ‘v1’, ‘k2’ : ‘v2’, ‘k3’ : ‘v3’} ,create a dictionary with the opposite mapping.
Write a program to create the dictionary .
Solution
x = { "k1" : "v1" , "k2" : "v2", "k3" : "v3"}
dic = { }
for i in x :
dic [ x[ i ] ] = i
print(dic)
Output/ Explanation: