Python 2:
res = dict((v,k) for k,v in a.iteritems())
Python 3 (thanks to @erik):
res = dict((v,k) for k,v in a.items())
More Related Contents:
- Reverse / invert a dictionary mapping
- What is the best way to implement nested dictionaries?
- How do you create nested dict in Python?
- Sort a list of tuples by second value, reverse=True and then by key, reverse=False
- Rename columns in Pandas based on a dictionary
- Function to return results in a dictionary in Python
- Why dict.get(key) instead of dict[key]?
- Remove duplicate dict in list in Python
- How to get a random value from dictionary?
- list to dictionary conversion with multiple values per key?
- In Python, how can you load YAML mappings as OrderedDicts?
- Creating a dictionary from a CSV file
- Hashing a dictionary?
- Right way to reverse a pandas DataFrame?
- How to dump a dict to a JSON file?
- TypeError: ‘dict_keys’ object does not support indexing
- Python: Checking if a ‘Dictionary’ is empty doesn’t seem to work
- 5 maximum values in a python dictionary
- Make dictionary from list with python [duplicate]
- Using a Python Dictionary as a Key (Non-nested)
- How do I return dictionary keys as a list in Python?
- Why can’t I use a list as a dict key in python? Exactly what can and cannot be used, and why?
- Python dictionary replace values
- How to get multiple dictionary values?
- python dict.add_by_value(dict_2)?
- Using Python class as a data container [closed]
- How can I convert string values from a dictionary, into int/float datatypes?
- How to type hint a dictionary with values of different types
- sorting list of nested dictionaries in python
- How to convert only numbers in a mixed list into float