-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecrypt-string-from-alphabet-to-integer-mapping.py
More file actions
42 lines (36 loc) · 1.18 KB
/
Copy pathdecrypt-string-from-alphabet-to-integer-mapping.py
File metadata and controls
42 lines (36 loc) · 1.18 KB
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
import string
class Solution:
def freqAlphabets(self, s: str) -> str:
data = []
for i,j in zip(range(10, 27), 'jklmnopqrstuvwxyz'):
data.append((str(i)+'#', j))
for i, j in zip(range(1, 10), 'abcdefghi'):
data.append((str(i), j))
for i, j in data:
s = s.replace(i, j)
return s
# data = []
# temp = ""
# for i in s:
# if i == "#":
# data.append(temp + "#")
# temp = ""
# else:
# temp += i
# if temp != "":
# data.append(temp)
# ans = ""
# for i in data:
# if i == '#':
# continue
# if i[-1] == '#':
# if len(i) > 2:
# for j in i[:-3]:
# ans += string.ascii_lowercase[int(j) - 1]
# ans += string.ascii_lowercase[int(i[-3:-1]) - 1]
# else:
# ans += string.ascii_lowercase[int(i[:-1]) - 1]
# else:
# for j in i:
# ans += string.ascii_lowercase[int(j) - 1]
# return ans