For Python 3:
my_dict2 = {y: x for x, y in my_dict.items()}
For Python 2, you can use
my_dict2 = dict((y, x) for x, y in my_dict.iteritems())
More Related Contents:
- Return a default value if a dictionary key is not available
- Dictionary: Get list of values for list of keys
- How to get a random value from dictionary?
- How to add multiple values to a dictionary key in python?
- How to add multiple values to a dictionary key?
- Merging two CSV files using Python
- How to print a dictionary’s key?
- Accessing dict_keys element by index in Python3
- Float values as dictionary key
- How can I get a random key-value pair from a dictionary?
- How can I get dictionary key as variable directly in Python (not by searching from value)?
- Why must dictionary keys be immutable?
- Using lambda function in python
- Make a dictionary with duplicate keys in Python
- Why do my Tkinter widgets get stored as None? [duplicate]
- How can you print a variable name in python? [duplicate]
- Multi-level defaultdict with variable depth?
- TypeError: ‘dict’ object is not callable
- python tuple to dict
- How to sort IP addresses stored in dictionary in Python?
- Change values in dict of nested dicts using items in a list?
- Dictionary best data structure for train routes?
- Using python map and other functional tools
- A python class that acts like dict
- Using Python class as a data container [closed]
- How can I convert string values from a dictionary, into int/float datatypes?
- Rename columns in Pandas based on a dictionary
- sorting list of nested dictionaries in python
- How to convert only numbers in a mixed list into float
- In what case would I use a tuple as a dictionary key? [closed]