일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 파이썬
- CodingTest
- collections
- 코테
- coding test
- 완전탐색
- Queue
- 연습문제
- Level2
- programmers
- time complexity
- lv4
- import re
- coding
- python
- lambda
- level4
- 코딩테스트
- BFS
- mysql
- sql
- Stack
- 시간복잡도
- itertools
- 데이터분석
- 코딩
- join
- 프로그래머스
- 조합
- counter
- Today
- Total
ror_coding
[Programmers] 이상한 문자 만들기 - 12930 본문
728x90
test case는 잘 풀리는데 제출시 예외 때문에 점수가 깎이는 문제 !
아마 공백 여러 개 일때가 예외 문제라서 일부러 마지막에 join으로 띄어쓰기 해주는 것 같다.
Question
문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 리턴하는 함수, solution을 완성하세요.
Point
- 단어만 저장하고 return 할 때 ' '.join(result) 사용해서 붙임.
Code
def solution(s):
result = []
for word in s.split(' '):
new_word = ''
for idx,w in enumerate(word):
if idx%2 ==0 : new_word += w.upper()
else : new_word += w.lower()
result.append(new_word)
return ' '.join(result)
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/021.gif)
now me
On my github
728x90
'Algorithm > Python' 카테고리의 다른 글
[Programmers] 최소직사각형 - 86491 (0) | 2024.10.06 |
---|---|
[Programmers] 삼총사 - 131705 (0) | 2024.10.06 |
[Programmers] 3진법 뒤집기 - 68935 (0) | 2024.10.04 |
[Programmer] 최대공약수와 최소공배수 - 12940 (1) | 2024.10.03 |
[Programmers] 행렬의 덧셈 - 12950 (0) | 2024.10.03 |