[프로그래머스]JadenCase 문자열 만들기(Python)

2022. 9. 15. 18:38·CodingTest/Programmers

0. 문제 링크

https://school.programmers.co.kr/learn/courses/30/lessons/12951

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

1. 문제 설명

1) 주어진 문자열을 공백 기준으로 분리하기

2) JadenCase로 바꾸기(첫 문자는 대문자, 나머지는 소문자)

 

2. 입출력

# input
s = "3people unFollowed me"

# output
return = "3people Unfollowed Me"

 

3. 코드

def solution(s):
    s = s.split(' ')
    for i in range(len(s)):
        s[i] = s[i].lower()                 # 모든 문자를 소문자로 바꾸기
        s[i] = s[i].capitalize()            # 첫 문자를 대문자로 바꾸기
    answer = ' '.join(s)                    # 리스트 한 문장으로 합치기
    return answer

 

실행 결과

 

4. 알게된 점

1) upper(), lower()

upper() : 숫자나 기호를 제외한 알파벳을 모두 대문자로 바꾸어 줌

lower() : 숫자나 기호를 제외한 알파벳을 모두 소문자로 바꾸어 줌

s = 'abcABC'

# upper()
print(s.upper())
>> ABCABC

# lower()
print(s.lower())
>> abcabc

 

2) capitalize(), title()

capitalize() : 맨 첫 글자를 대문자로 변환

title() : 알파벳 외의 문자로 나누어진 단어의 첫 글자를 대문자로 변환

s = 'abc-def ghi'

# capitalize()
print(s.capitalize())
>> Abc-def ghi

# title()
print(s.title())
>> Abc-Def Ghi

 

5. Github

https://github.com/iihye/Algorithm/blob/main/Programmers/jadencase_string.py

 

GitHub - iihye/Algorithm

Contribute to iihye/Algorithm development by creating an account on GitHub.

github.com

 

728x90
저작자표시 비영리 변경금지 (새창열림)

'CodingTest > Programmers' 카테고리의 다른 글

[프로그래머스]올바른 괄호(Python)  (0) 2022.09.17
[프로그래머스]최솟값 만들기(Python)  (0) 2022.09.16
[프로그래머스]최댓값과 최솟값(Python)  (0) 2022.09.14
[프로그래머스]성격 유형 검사하기(Python)  (0) 2022.09.06
[프로그래머스]124 나라의 숫자(Python)  (0) 2022.08.26
'CodingTest/Programmers' 카테고리의 다른 글
  • [프로그래머스]올바른 괄호(Python)
  • [프로그래머스]최솟값 만들기(Python)
  • [프로그래머스]최댓값과 최솟값(Python)
  • [프로그래머스]성격 유형 검사하기(Python)
iihye_
iihye_
  • iihye_
    hye-log
    iihye_
    • 분류 전체보기 (297) N
      • Development (20) N
        • Java (5) N
        • Python (5)
        • React (4)
        • Next.js (1)
        • JavaScript (4)
        • CSS (1)
      • Infra (15)
        • Docker (1)
        • Jenkins (2)
        • Nginx (3)
        • JBoss (1)
        • Windows (3)
        • Linux (3)
        • Kafka (2)
      • Database (1)
        • MongoDB (1)
      • Tools (2)
        • Git (0)
        • Github (1)
        • Document (1)
      • CodingTest (125)
        • Programmers (38)
        • Baekjoon (52)
        • SWEA (27)
        • Jungol (4)
        • Codetree (1)
        • Goorm (3)
      • Education (99)
        • SSAFY 10기 (5)
        • AI Tech 4기 (94)
      • NomadCoder (35)
        • (JS)크롬 앱 만들기 (35)
      • Notice (0)
  • 링크

    • Github
  • 인기 글

  • 최근 글

  • 전체
    오늘
    어제
  • hELLO· Designed By정상우.v4.10.5
iihye_
[프로그래머스]JadenCase 문자열 만들기(Python)
상단으로

티스토리툴바