0

I'd like to flip the keys and the values in a dictionary.

Say I have this dictionary:

positions = {'secretary' : 'Jessica', 'IT manager' : 'Matt', 'sales worker' : 'Linda', 'boss' : 'Chris'}

and I want this:

employees = {'Jessica' : 'secretary', 'Matt' : 'IT manager', 'Linda' : 'sales worker', 'Chris' : 'boss'}

Is there an easy way to create "employees" such as employees = positions.function() Thanks for the help.

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by Ene Uran
0

Make sure your dictionary values are unique and immutable when you do this:

inverted_dict1 = dict([(v, k) for (k, v) in dict1.iteritems()])
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.