-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecode.py
More file actions
32 lines (20 loc) · 729 Bytes
/
Copy pathdecode.py
File metadata and controls
32 lines (20 loc) · 729 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
def decode(s):
"""Decode a string."""
# may need to split assertion. valid inputs can have numbers after 0-index.
# assert s[0].isdigit() and s[1:].isalpha(), "String must contain a sequence that starts with a number and end with letter(s)."
# will need to store ints as slice starts. grab by index?
# at end, need to concatenate all valid letters
# slice_indices = []
# i = 0
# for i in range(len(s)):
# if s[i].isdigit():
# slice_indices.append(i)
word = "" # init empty str
i = 0
while i < len(s):
num_to_skip = int(s[i])
i += num_to_skip + 1
word += s[i]
i += 1
return word
print decode("0t3jsme1hs0t") # 'test'