KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: Python: Best Way to Exchange Keys with Values in a Dictionary? Suppose that I need to swap keys for values in dictionary. This is what I have in mind (Assuming that the values' value is unique): >>> my_dict = {'x':1, 'y':2, 'z':3} >>> my_dict2 = {} >>> for key, val in my_dict.items(): my_dict2[val] = key Is there any other efficient way to do it?
Tags (comma-separated)
Save Edits
Cancel