i am trying to replace characters in a text file, the code works but it just seems too long. I was wondering if there is a different way to do this?
(It is a good way for me to learn a better way than just a long repetivite way)
Thanks
with open('documento.txt', 'r') as file:
filedata = file.read()
filedata = filedata.replace('+', 'e')
filedata = filedata.replace('P', 'a')
filedata = filedata.replace('B', 'o')
filedata = filedata.replace('N', 's')
filedata = filedata.replace('K', 'n')
filedata = filedata.replace('X', 'r')
filedata = filedata.replace('Q', 'i')
filedata = filedata.replace('T', 'l')
filedata = filedata.replace('*', 'd')
filedata = filedata.replace('Y', 'u')
filedata = filedata.replace('_', 'c')
filedata = filedata.replace('V', 't')
filedata = filedata.replace('H', 'm')
filedata = filedata.replace('D', 'q')
filedata = filedata.replace('M', 'h')
filedata = filedata.replace('R', 'j')
with open('documento.txt', 'w') as file:
file.write(filedata)