프로그래머스. 연습문제. Level 2. JadenCase 문자열 만들기 파이썬 풀이
문제링크 https://programmers.co.kr/learn/courses/30/lessons/12951
def solution(s):
answer = ''
s = list(s)
blank = []
for i in range(len(s)):
if s[i].isalpha(): # 알파벳이라면 소문자로 변환
s[i] = s[i].lower()
if s[i] == " ": # 공백이라면 인덱스를 blank 배열에 저장
blank.append(i)
# 공백 인덱스를 돌며
for b in blank:
if b+1 >= len(s): # 공백 다음이 범위를 벗어나면 break
break
elif s[b+1].isdigit(): # 첫 문자가 숫자라면 다음 글자 소문자로 바꿈
s[b+2] = s[b+2].lower()
elif not s[b+1].isalpha(): # 다음 문자가 알파벳이 아니라면 continue
continue
elif s[b+1].isalpha: # 첫 문자가 알파벳이라면 대문자로
s[b+1] = s[b+1].upper()
# 제일 처음 문자가 알파벳이라면 대문자로 변환
if s[0].isalpha():
s[0] = s[0].upper()
answer = "".join(s)
return answer