Balikkan Kamus Python
inv_map = {v: k for k, v in my_map.items()}
Busy Boar
inv_map = {v: k for k, v in my_map.items()}
d = {'a':1, 'b':2, 'c':3}
inverted_d = {}
for k, v in d.items():
inverted_d[v] = k
orig = { 1:'A', 2:'B', 3:'C' }
new = dict(zip(orig.values(), orig.keys()))
new == {'A': 1, 'B': 2, 'C': 3} #True
# invert a dictionary
def inv_dict(obj):
return { value: key for key, value in obj.items() }
d = {'apple':1, 'oranges':2, 'bananas':3}
print(d)
print(inv_dict(d))
# Output:
# {1: 'apple', 2: 'oranges', 3: 'bananas'}