Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. match_table = {
  2.     'А': ['A'],   'а': ['a'],
  3.     'Б': ['B'],   'б': ['b'],
  4.     'В': ['V'],   'в': ['v'],
  5.     'Г': ['G'],   'г': ['g'],
  6.     'Д': ['D'],   'д': ['d'],
  7.     'Е': ['E', 'Ye'],
  8.     'е': ['e', 'ye'],
  9.     'Ё': ['E', 'Yo'],
  10.     'ё': ['e', 'yo'],
  11.     'Ж': ['Zh'],  'ж': ['zh'],
  12.     'З': ['Z'],   'з': ['z'],
  13.     'И': ['I'],   'и': ['i'],
  14.     'Й': ['J', 'Jj', 'I', 'Y'],
  15.     'й': ['j', 'jj', 'i', 'y'],
  16.     'К': ['K'],   'к': ['k'],
  17.     'Л': ['L'],   'л': ['l'],
  18.     'М': ['M'],   'м': ['m'],
  19.     'Н': ['N'],   'н': ['n'],
  20.     'О': ['O'],   'о': ['o'],
  21.     'П': ['P'],   'п': ['p'],
  22.     'Р': ['R'],   'р': ['r'],
  23.     'С': ['S'],   'с': ['s'],
  24.     'Т': ['T'],   'т': ['t'],
  25.     'У': ['U'],   'у': ['u'],
  26.     'Ф': ['F'],   'ф': ['f'],
  27.     'Х': ['H', 'Kh'],
  28.     'х': ['h', 'kh'],
  29.     'Ц': ['C', 'Ts'],  
  30.     'ц': ['c', 'ts'],
  31.     'Ч': ['Ch'],  'ч': ['ch'],
  32.     'Ш': ['Sh'],  'ш': ['sh'],
  33.     'Щ': ['Shch', 'Shh'],
  34.     'щ': ['shch', 'shh'],
  35.     'Ъ': [''],    'ъ': [''],
  36.     'Ы': ['Y'],   'ы': ['y'],
  37.     'Ь': ['\''],  'ь': ['\''],
  38.     'Э': ['E'],   'э': ['e'],
  39.     'Ю': ['Yu'],  'ю': ['yu'],
  40.     'Я': ['Ya'],  'я': ['ya'],
  41. }
  42.  
  43. def translit(russian_string: str):
  44.     def translit_recursive(prefix, rest_part):
  45.         result = []
  46.         for i in range(len(rest_part)):
  47.             symbol = rest_part[i]
  48.             if symbol not in match_table:
  49.                 prefix += symbol
  50.             else:
  51.                 for next_symbol in match_table[symbol]:
  52.                     result.extend(translit_recursive(prefix+next_symbol, rest_part[i+1:]))
  53.                 return result
  54.         return [prefix]
  55.    
  56.     return translit_recursive('', russian_string)
  57.  
  58. while True:
  59.     string = input()
  60.     if string == 'end':
  61.         break
  62.     else:
  63.         print(translit(string))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement