-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathz018.py
More file actions
executable file
·46 lines (38 loc) · 862 Bytes
/
z018.py
File metadata and controls
executable file
·46 lines (38 loc) · 862 Bytes
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
#!/usr/bin/env python
def expand(s):
L = []
for c in s:
if c not in "0123456789":
L.append(c)
mem = c
else:
for x in range(int(c)):
L.append(mem)
return "".join(L)
# def shorten(s):
# L = list(s)
# index = 0
# for i in range(len(L)):
# if i > 0:
# if L[i] == L[i - 1]:
# L.remove(L[i])
# print("popped: " + L[i])
# return "".join(L)
def shorten(s):
L = list(s)
res = []
mem = 1
for i in range(len(L)):
if L[i - 1] != L[i]:
res.append(str(mem))
res.append(L[i])
mem = 1
else:
mem += 1
x = str("".join(res))
return x[1:] + x[0]
a = "a2b3c1"
print(expand(a))
a = "bbbbbcccaaa"
print(shorten(a))
# print(int(Decimala[0]))