Possible duplicate:
Python: best way to exchange keys with values ββin a dictionary?
Suppose I need to swap keys for values ββin a dictionary.
This is what I mean (suppose the 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 effective way to do this?
riza Jul 06 '09 at 15:41 2009-07-06 15:41
source share