๊ธ€ ์ž‘์„ฑ์ž: ํƒ์‹œ ์šด์ „์‚ฌ
๋ฐ˜์‘ํ˜•

๐Ÿค” ์ด์ƒํ•œ ๋ฌธ์ž ๋งŒ๋“ค๊ธฐ

๋ฌธ์ œ ์„ค๋ช…

๋ฌธ์ž์—ด s๋Š” ํ•œ ๊ฐœ ์ด์ƒ์˜ ๋‹จ์–ด๋กœ ๊ตฌ์„ฑ๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ ๋‹จ์–ด๋Š” ํ•˜๋‚˜ ์ด์ƒ์˜ ๊ณต๋ฐฑ๋ฌธ์ž๋กœ ๊ตฌ๋ถ„๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๊ฐ ๋‹จ์–ด์˜ ์ง์ˆ˜๋ฒˆ์งธ ์•ŒํŒŒ๋ฒณ์€ ๋Œ€๋ฌธ์ž๋กœ, ํ™€์ˆ˜๋ฒˆ์งธ ์•ŒํŒŒ๋ฒณ์€ ์†Œ๋ฌธ์ž๋กœ ๋ฐ”๊พผ ๋ฌธ์ž์—ด์„ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”.

์ œํ•œ ์‚ฌํ•ญ

  • ๋ฌธ์ž์—ด ์ „์ฒด์˜ ์ง/ํ™€์ˆ˜ ์ธ๋ฑ์Šค๊ฐ€ ์•„๋‹ˆ๋ผ, ๋‹จ์–ด(๊ณต๋ฐฑ์„ ๊ธฐ์ค€)๋ณ„๋กœ ์ง/ํ™€์ˆ˜ ์ธ๋ฑ์Šค๋ฅผ ํŒ๋‹จํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

๐Ÿ˜ƒ ๋‚˜์˜ ํ’€์ด

def solution(s):
    answer = ''
    lst = s.split(' ')
    for idx, string in enumerate(lst):
        for i in range(len(string)):
            if i%2 == 0:
                string = string[:i] + string[i].upper() + string[i+1:]
            else: string = string[:i] + string[i].lower() + string[i+1:]
        lst[idx] = string
    return " ".join(lst)

์šฐ์„  split(' ') ๋ฉ”์†Œ๋“œ์„ ์ด์šฉํ•ด์„œ ๋นˆ์นธ์„ ๊ธฐ์ค€์œผ๋กœ ๋ฐฐ์—ด์— ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  ๊ฐ ๋ฌธ์ž์—ด๋งˆ๋‹ค ์งํ™€์— ๋งž๋Š” ์ž‘์—…์„ ์‹œํ–‰ํ•ด์ค๋‹ˆ๋‹ค. ์—ฌ๊ธฐ์„œ ๋‹ค์‹œ ํ•œ ๋ฒˆ ์ƒ๊ธฐ์‹œํ‚ค์ž๋ฉด ๋ฌธ์ž์—ด์˜ ๊ฒฝ์šฐ ๋ฐฐ์—ด๊ณผ ๋‹ฌ๋ฆฌ ๊ทธ๋ƒฅ ๋Œ€์ž…ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ ๋ฌธ์ž๋ฅผ ๋ณ€ํ™˜ํ•˜์ง€ ๋ชปํ•ฉ๋‹ˆ๋‹ค. ๋Œ€์‹  ์œ„์™€ ๊ฐ™์€ ๋ฐฉ๋ฒ•์œผ๋กœ string ์ „์ฒด๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•˜๊ฑฐ๋‚˜ ๋ฌธ์ž์—ด์„ ๋ฐฐ์—ด๋กœ ๋ฐ”๊ฟ”์„œ ์ž‘์—…ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋งˆ์ง€๋ง‰์œผ๋กœ, ์ด์ƒํ•œ ๋ฌธ์ž๊ฐ€ ๋œ ๋ฌธ์ž์—ด๋“ค์„ " ".join(lst) ๋ฉ”์†Œ๋“œ๋ฅผ ์ด์šฉํ•˜์—ฌ ๋ฌธ์ž์—ด ์‚ฌ์ด ๋นˆ์นธ์ด ์žˆ๋Š” ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

๋ฐ˜์‘ํ˜•