Search code examples
pythonc++documenttranslate

I have a document with a unique alphabet, how can I translate it?


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?


Solution

  • 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!!!