-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.py
49 lines (45 loc) · 1.1 KB
/
map.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
import doctest
def __remapAlphabet__(char):
"""
>>> __remapAlphabet__('a')
'c'
>>> __remapAlphabet__('x')
'z'
>>> __remapAlphabet__('y')
'a'
>>> __remapAlphabet__('z')
'b'
>>> __remapAlphabet__(' ')
' '
"""
remap_char = ""
alphabet = ['a', 'b', 'c', 'd',
'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p',
'q', 'r', 's', 't',
'u', 'v', 'w', 'x',
'y', 'z']
try:
order = alphabet.index(char)
if order < 24:
remap = order + 2
remap_char = alphabet[remap]
elif 24 <= order < len(alphabet):
remap = order + 2 - len(alphabet)
remap_char = alphabet[remap]
except:
remap_char = char
return remap_char
def wordRemap(word):
""" Word Remapping
>>> wordRemap('koe')
'mqg'
>>> wordRemap('abc')
'cde'
"""
remap_word = map(__remapAlphabet__, word)
return ''.join(remap_word)
if __name__ == "__main__":
doctest.testmod()