Using collections.defaultdict
:
from collections import defaultdict
reversed_dict = defaultdict(list)
for key, value in mydict.items():
reversed_dict[value].append(key)
More Related Contents:
- Convert array dictionary to a dictionary python
- Function to return results in a dictionary in Python
- Convert a String representation of a Dictionary to a dictionary?
- 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?
- Writing a dictionary to a csv file with one line for every ‘key: value’
- How to sort objects by multiple keys?
- List of dicts to/from dict of lists
- Appending a dictionary to a list – I see a pointer like behavior
- Converting Python dict to kwargs?
- Using a dictionary to select function to execute
- count the number of occurrences of a certain value in a dictionary in python?
- TypeError: ‘dict_keys’ object does not support indexing
- 5 maximum values in a python dictionary
- Creating a list of dictionaries with same keys? [duplicate]
- Make dictionary from list with python [duplicate]
- Using a Python Dictionary as a Key (Non-nested)
- Is there a recursive version of the dict.get() built-in?
- How can one make a dictionary with duplicate keys in Python?
- 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?
- Sort a list of tuples by second value, reverse=True and then by key, reverse=False
- python dict.add_by_value(dict_2)?
- type=dict in argparse.add_argument()
- How do I merge dictionaries together in Python?
- Python: Writing Nested Dictionary to CSV