[6 kyu] Split Strings
Question
Sample Tests
My Answer (accepted)
def solution(s):
index = 0
ans_list = list()
while index < len(s) - 1:
ans_list.append(s[index:index+2])
index += 2
if len(s) % 2:
ans_list.append(s[-1] + "_")
print(ans_list)
return ans_list
Suggested Answer
def solution(s):
result = []
if len(s) % 2:
s += '_'
for i in range(0, len(s), 2):
result.append(s[i:i+2])
return result