Skip to content

Instantly share code, notes, and snippets.

@ldsad7
Last active May 16, 2019 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ldsad7/27ed1b0d04ea10486c218919145e24bb to your computer and use it in GitHub Desktop.
Save ldsad7/27ed1b0d04ea10486c218919145e24bb to your computer and use it in GitHub Desktop.
def detransliterate(string):
from_list = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'
to_list = 'a,b,v,g,d,e,jo,zh,z,i,y,k,l,m,n,o,p,r,s,t,u,f,kh,c,ch,sh,shh,jhh,ih,jh,eh,ju,ja,A,B,V,G,D,E,JO,ZH,Z,I,Y,K,L,M,N,O,P,R,S,T,U,F,KH,C,CH,SH,SHH,JHH,IH,JH,EH,JU,JA'.split(',')
detransliterated_string = ''
index_of_symbol = 0
while index_of_symbol < len(string):
was_combination = 0
for i in range(3, 0, -1):
if string[index_of_symbol:index_of_symbol+i] in to_list:
index = to_list.index(string[index_of_symbol:index_of_symbol+i])
detransliterated_string += from_list[index]
index_of_symbol += i
was_combination = 1
break
if not was_combination:
detransliterated_string += string[index_of_symbol]
index_of_symbol += 1
return detransliterated_string
def transliterate(string):
from_list = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюяАБВГДЕЁЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯ'
to_list = 'a,b,v,g,d,e,jo,zh,z,i,y,k,l,m,n,o,p,r,s,t,u,f,kh,c,ch,sh,shh,jhh,ih,jh,eh,ju,ja,A,B,V,G,D,E,JO,ZH,Z,I,Y,K,L,M,N,O,P,R,S,T,U,F,KH,C,CH,SH,SHH,JHH,IH,JH,EH,JU,JA'.split(',')
transliterated_string = ''
for symbol in string:
if symbol in from_list:
index = from_list.index(symbol)
transliterated_string += to_list[index]
else:
transliterated_string += symbol
return transliterated_string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment