I want to reverse the key mapping for the following dictionary:
joy2gurbaniakhar = {'T':'a', 'n':'A', 'J':'e', ';':'s', 'j':'h', 'e':'k', 'y':'K', 'r':'g', 'x':'G', 'C':'|', 'u':'c', 'S':'c', 'i':'j', 'M':'J', 'R':'\\', 'N':'t', 'm':'T', 'v':'f', 'Y':'F', 'D':'x', 's':'q', 'E':'Q', 'd':'d', 'X':'D', 'B':'n', 'g':'p', 'c':'P', 'p':'b', 'G':'B', 'w':'m', ':':'X', 'o':'r', 'b':'l', 't':'v', 'V':'V', 'ô':'S', 'õ':'^', 'ö':'Z', '÷':'z', 'ø':'&', 'ÿ':'L', 'z':'M', 'k':'w', 'h':'I', 'f':'i', '/':'y', 'q':'R', 'H':'.', '[':'u', '{':'U', '\'':'o', '\"':'O', 'K':'W', 'F':'-','.':'[', 'A':'N', 'Z':'~', '?':'ੈ', '+':'Y', 'ý':'Å', 'ú':'E', 'J[':'ey', 'T{':'aU', 'T[':'au', 'Jh':'eI', 'fJ':'ie', 'nk':'Aw', 'n\"':'AO', 'n?':'AY', 'W':'hY', 'ù':'ƒ'}
I have used following code to reverse the mapping:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
reverse_maping = {v: k for k, v in joy2gurbaniakhar.items()}
print reverse_maping
It works well but, I am getting the following mapping which contain the Unicode values of special characters and incorrect serial order of dictionary, like following:
reverse_maping = {'V': 'V', '\xc3\x85': '\xc3\xbd', 'w': 'k', 'Y': '+', 'ey': 'J[', 'ie': 'fJ', 'eI': 'Jh', '&': '\xc3\xb8', '-': 'F', '.': 'H', 'aU': 'T{', 'b': 'p', 'A': 'n', '\xc6\x92': '\xc3\xb9', 'B': 'G', 'E': '\xc3\xba', 'D': 'X', 'G': 'x', 'F': 'Y', 'I': 'h', 'K': 'y', 'J': 'M', 'M': 'z', 'L': '\xc3\xbf', 'O': '"', 'N': 'A', '\xe0\xa9\x88': '?', 'P': 'c', 'S': '\xc3\xb4', 'R': 'q', '\xe2\x80\x8di': 'f', 'T': 'm', 'W': 'K', 'x': 'D', 'AY': 'n?', 'X': ':', '[': '.', 'Z': 'ö', 'U': '{', '\\': 'R', '^': '\xc3\xb5', 'a': 'T', 'Q': 'E', 'c': 'u', 'hY': 'W', 'e': 'J', 'd': 'd', 'g': 'r', 'f': 'v', 'AO': 'n"', 'h': 'j', 'k': 'e', 'j': 'i', 'm': 'w', 'l': 'b', 'o': "'", 'n': 'B', 'q': 's', 'p': 'g', 's': ';', 'r': 'o', 'u': '[', 't': 'N', 'Aw': 'nk', 'v': 't', 'y': '/', 'au': 'T[', 'z': '÷', '|': 'C', '~': 'Z'}
It Should be like:
reverse_mapping = {'a':'T', 'A':'n', 'e':'J'.......}