Answers for "reverse python dictionary"

4

invert dictionary python

inv_map = {v: k for k, v in my_map.items()}
Posted by: Guest on August-23-2020
3

reverse dictionary python

inv_map = {v: k for k, v in my_map.items()}
Posted by: Guest on February-20-2021
0

reverse python dictionary

inv_map = {v: k for k, v in my_map.iteritems()}
Posted by: Guest on June-10-2021
1

how to reverse a dictionary in python

def inverse_dict(my_dict):
    """
    the func get a dictinary and reverse it, the keys become values and the values become keys.
    :param my_dict: the dictinary that need to be reversed.
    :return: a VERY pretty dictionary.
    """
    result_dict = {}
    for key, value in my_dict.items():
        if not value in result_dict.keys():
            result_dict[value] = []
        result_dict[value].append(key)
    return result_dict, print(result_dict)
Posted by: Guest on May-17-2020

Code answers related to "reverse python dictionary"

Browse Popular Code Answers by Language