Home PS) 이상한 문자 만들기
Post
Cancel

PS) 이상한 문자 만들기

출처
: Programmers

문제

문자열 s는 한 개 이상의 단어로 구성되어 있습니다. 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 각 단어의 짝수번째 알파벳은 대문자로, 홀수번째 알파벳은 소문자로 바꾼 문자열을 리턴하는 함수, solution을 완성하세요.

(생략)

나의 풀이

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
29
30
def solution(s):
    splited_list = s.split(' ')
    size = len(splited_list)

    answer = ' '.join([''.join((
        map(
            (lambda x: splited_list[j][x].upper()
                            if x % 2 == 0
                            else splited_list[j][x].lower()),
                        range(len(splited_list[j]))
            )
                                ))
           for j in range(size)])

    # for i in range(size):
    #     each_size = len(splited_list[i])
    #     for j in range(each_size):
    #         temp = splited_list[i]
    #         if (j % 2 == 0):
    #             splited_list[i] = (temp[:j] +
    #                                temp[j].upper() +
    #                                temp[j+1:])
    #         else:
    #             splited_list[i] = (temp[:j] +
    #                                temp[j].lower() +
    #                                temp[j+1:])
    # print(splited_list)
    # print(True)

    return answer



다른 사람들의 풀이

1

(출처: 프로그래머스 스쿨 다른사람 풀이)

Contents