Algorithm/codewars

Format a string of names like 'Bart, Lisa & Maggie'. 답안

Bonita SY 2021. 4. 1. 19:31
728x90
반응형

문제)

www.codewars.com/kata/53368a47e38700bd8300030d/train/python

 

Codewars: Achieve mastery through challenge

Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential.

www.codewars.com

 

내가 푼 답)

def namelist(names):
    result = ''
    i = 1
    for name in names:
        result += name['name']
        if (i <= (len(names) - 2)):
            result += ', '
        elif (i == (len(names) - 1)):
            result += ' & '
        i += 1
    return result

 

테스트 결과)

 

마음에 드는 다른 사람이 푼 답)

728x90
반응형

'Algorithm > codewars' 카테고리의 다른 글

Take a Ten Minute Walk 답안  (0) 2021.04.01
Credit Card Mask 답안  (0) 2021.04.01
Catching Car Mileage Numbers 답안  (0) 2021.04.01
Adding Big Numbers 답안  (0) 2021.03.30
Directions Reduction 답안  (0) 2021.03.30