Advertisement
atm-irbis

to_rus

May 9th, 2013
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.34 KB | None | 0 0
  1. #-*- coding: utf-8 -*-
  2. import sys
  3.  
  4. class SwitchKey:
  5.     def __init__(self):
  6.         self.codes =  {
  7.     'Q':u'й',
  8.     'W':u'ц',
  9.     'E':u'у',
  10.     'R':u'к',
  11.     'T':u'е',
  12.     'Y':u'н',
  13.     'U':u'г',
  14.     'I':u'ш',
  15.     'O':u'щ',
  16.     'P':u'з',
  17.     '{':u'х',
  18.     '}':u'ъ',
  19.     'A':u'ф',
  20.     'S':u'ы',
  21.     'D':u'в',
  22.     'F':u'а',
  23.     'G':u'п',
  24.     'H':u'р',
  25.     'J':u'о',
  26.     'K':u'л',
  27.     'L':u'д',
  28.     ';':u'ж',
  29.     "'":u'э',
  30.     'Z':u'я',
  31.     'X':u'ч',
  32.     'C':u'с',
  33.     'V':u'м',
  34.     'B':u'и',
  35.     'N':u'т',
  36.     'M':u'ь',
  37.     ',':u'б',
  38.     '.':u'ю',
  39.     '`':u'ё',
  40.     }
  41.         self.__update__()
  42.  
  43.     def __inverse__(self):
  44.         key = self.codes.keys()
  45.         value = self.codes.values()
  46.  
  47.         def lower(s):
  48.             return s.lower()
  49.         def upper(s):
  50.             return s.upper()
  51.  
  52.         nkey = map(upper,value)
  53.         nval = map(lower,key)
  54.         return dict(zip(nkey,nval))
  55.  
  56.     def __update__(self):
  57.         dict = self.__inverse__()
  58.         self.codes.update(dict)
  59.  
  60.     def switch(self,string):
  61.         key = self.codes.keys()
  62.         s = ''
  63.         for i in string.upper():
  64.             if i in key:
  65.                 s += self.codes[i]
  66.             else:
  67.                 s += i
  68.         return s
  69.  
  70. x = SwitchKey()
  71. print x.switch(sys.argv[1].decode('utf'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement