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