0

I have a document filled with weird characters, but I have the counterpart of the letters in another document.

Eg.

⟷ = a
⇳ = b
⤚ = c

etc...

I think that I can do this by using a dictionary, and a simple swap algorythm, but I'm still a newbie in programming. Do you think that's a good idea? How can I translate the whole text (preferably using Python or C++), without having to use MS Word's built in "swap" tool?

BeanieBarrow
  • 512
  • 2
  • 11

2 Answers2

2

Yes dictionary is an option. You could also look at string.maketrans() method to do that.

from string import maketrans

intab = "aeiou"
outtab = "12345"
trantab = maketrans(intab, outtab)

str = "this is string example....wow!!!";
print(str.translate(trantab))

will give output

th3s 3s str3ng 2x1mpl2....w4w!!!
leotrubach
  • 1,509
  • 12
  • 15
0

You can you translate method in python from string module:

from string import maketrans

in_letters = "abc"               # and so on, you can add more letters
out_letters = ''.join(['⟷', '⇳', '⤚'])
t = maketrans(in_letters, out_letters)

with open('file.txt') as f:      # specify necessary filename
    text = f.read()
    translation = str.translate(t)
    print(translation)
Lev Zakharov
  • 2,409
  • 1
  • 10
  • 24