Q. Given the dictionary x = {‘k1’: ‘v1’, ‘k2’ : ‘v2’, ‘k3’ : ‘v3’} ,create a dictionary with the opposite mapping.

Write a program to create the dictionary.


You can understand by Watching video :-



Answer :-

x = { "k1" : "v1" , "k2" : "v2", "k3" : "v3"}
dic = { }
for i in x :
    dic [ x[ i ] ] = i
print(dic)

Output :-

{'v1': 'k1', 'v2': 'k2', 'v3': 'k3'}
>>> 


8 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. it wasn't producing the correct output

    ReplyDelete
    Replies
    1. It is producing desire output. So, Please check it in your IDLE Python.

      Delete
  2. Intentionally clicking ads😄
    Great content thank you!

    ReplyDelete
  3. didnt understand the 4th line

    ReplyDelete
    Replies
    1. Please watch the video for proper explanation.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post