“Wie man ein Wörterbuch in Python umgeht” Code-Antworten

Invertary Wörterbuch Python

inv_map = {v: k for k, v in my_map.items()}
Busy Boar

Reverse Python Dictionary

inv_map = {v: k for k, v in my_map.iteritems()}
Alaa Sedeeq

Python Reverse Dictionary

inv_map = {v: k for k, v in my_map.iteritems()}
Eilay Koren

Wie man ein Wörterbuch in Python umgeht

def inverse_dict(my_dict):
    """The function accepts a dictionary as a parameter.
    The function returns a new dictionary with "inverted" mapping:
    each key in the transmitted dictionary is a value in the returned dictionary
    and value entry in the transmitted dictionary is a key in the returned dictionary.
    :param my_dict: dictionary
    :type my_str: string
    :return: Dictionary
    :rtype: Dictionary
    """
    new_dict = {}                                   # create empty Dictionary
    for itm1 in my_dict.items():
        lst = []
        for itm2 in my_dict.items():
            if itm2[1] == itm1[1]:
                lst.append(itm2[0])
        new_dict[itm1[1]] = sorted(lst)

    return new_dict
Smoggy Sheep

Ähnliche Antworten wie “Wie man ein Wörterbuch in Python umgeht”

Fragen ähnlich wie “Wie man ein Wörterbuch in Python umgeht”

Weitere verwandte Antworten zu “Wie man ein Wörterbuch in Python umgeht” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen