programmers | Lv2. JadenCase 문자열 만들기 [Python]

yeonk·2022년 3월 5일
0

algorithm

목록 보기
60/88
post-thumbnail

💡 Python 3






🔗 문제

JadenCase 문자열 만들기 [Link]






💻 코드

def solution(s):
    sl = list(s.lower())
    result = ''
    count = 0
    for c in sl:
        if count == 0 and c.isalpha():
            result += c.upper()
            count += 1
        elif c == ' ':
            result += c
            count = 0
        else:
            result += c
            count += 1
    return result






💥 다른 사람 코드

문제 개편으로 지금은 통과되지 않지만 title 함수에 대해 알게 되어 적어본다.

def Jaden_Case(s):
    # 함수를 완성하세요
    return s.title()






참고 자료

파이썬 문자열 함수 - upper, lower, title, split 문자열 분리하기

0개의 댓글