Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

swap keys and values in dictionary python

my_dict = {'x':1, 'y':2, 'z':3}
my_swapped_dict = {v: k for k, v in my_dict.items()}
#{1: 'x', 2: 'y', 3: 'z'}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #swap #keys #values #dictionary #python
ADD COMMENT
Topic
Name
4+7 =