물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Split Strings

BEstyle 2022. 9. 29. 12:47

DESCRIPTION:

Complete the solution so that it splits the string into pairs of two characters. If the string contains an odd number of characters then it should replace the missing second character of the final pair with an underscore ('_').

Examples:

* 'abc' =>  ['ab', 'c_']
* 'abcdef' => ['ab', 'cd', 'ef']

def solution(s):
    if len(s)%2==1:
        s+='_'
    print(s)
    alist=[]
    while s!="":
        alist.append(s[0:2])
        s=s[2:]
        print(alist)
        print(s)
    return alist

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Find the missing letter  (1) 2022.09.29
Shortest Word  (0) 2022.09.29
Good vs Evil  (0) 2022.09.28
Disemvowel Trolls  (0) 2022.09.28
Sum of Digits/Digital Root  (0) 2022.09.28