https://programmers.co.kr/learn/courses/30/lessons/72410
ํ์ด
def solution(new_id):
# 1๋จ๊ณ
new_id = new_id.lower()
# 2๋จ๊ณ
answer = ''
for word in new_id:
if word.isalnum() or word in '-_.':
answer += word
# 3๋จ๊ณ
while '..' in answer:
answer = answer.replace('..', '.')
# 4๋จ๊ณ
answer = answer[1:] if answer[0] == '.' and len(answer) > 1 else answer
answer = answer[:-1] if answer[-1] == '.' else answer
# 5๋จ๊ณ
answer = 'a' if answer == '' else answer
# 6๋จ๊ณ
if len(answer) >= 16:
answer = answer[:15]
if answer[-1] == '.':
answer = answer[:-1]
# 7๋จ๊ณ
if len(answer) <= 3:
answer = answer + answer[-1] * (3-len(answer))
return answer
- 1๋จ๊ณ
upper() : ๋ชจ๋ ๋๋ฌธ์๋ก ๋ฐ๊ฟ์ฃผ๋ ๋ฉ์๋
lower() : ๋ชจ๋ ์๋ฌธ์๋ก ๋ฐ๊ฟ์ฃผ๋ ๋ฉ์๋
์์ด๋๋ฅผ ๋ชจ๋ ์๋ฌธ์๋ก ๋ฐ๊ฟ์ฃผ๊ธฐ
- 2๋จ๊ณ
isalnum() : ๋ฌธ์์ด์ด ์ํ๋ฒณ([a-zA-Z])๊ณผ ์ซ์([0-9])๋ก๋ง ๊ตฌ์ฑ๋์๋์ง ํ์ธํ๋ ํ์ด์ฌ ๋ฌธ์์ด ๋ฉ์๋
- 3๋จ๊ณ
replace('a', 'b') : a๋ฅผ b๋ก ๋ฐ๊ฟ์ฃผ๋ ๋ฉ์๋
'..'์ด ์์ด์ง ๋ ๊น์ง '.'๋ก ๋ฐ๊ฟ์ฃผ๊ธฐ
- 4๋จ๊ณ
answer[a:b] : a๋ถํฐ b-1 ๊น์ง ์๋ฅด๋ ๋ฌธ์์ด ์ฌ๋ผ์ด์ฑ
์์ด๋์ ์ฒ์์ด๋ ๋ง์ง๋ง์ด '.' ์ด๋ฉด ์ฒ์์ด๋ ๋ง์ง๋ง์ ์๋'.' ์ ๊ฑฐ
- 5๋จ๊ณ
์์ด๋๊ฐ ๋น์ด์๋ค๋ฉด 'a' ๋ก ๋ฐ๊ฟ์ฃผ๊ธฐ
- 6๋จ๊ณ
์์ด๋์ ๊ธธ์ด๊ฐ 16์ด์์ด๋ฉด ์ฒซ 15๊ฐ์ ๋ฌธ์๋ฅผ ์ ์ธํ ๋๋จธ์ง ๋ฌธ์๋ค์ ๋ชจ๋ ์ ๊ฑฐ
- 7๋จ๊ณ
์์ด๋์ ๊ธธ์ด๊ฐ 2์๋ฆฌ ์ดํ์ด๋ฉด ์์ด๋์ ๋ง์ง๋ง ๋ฌธ์๋ฅผ ์์ด๋์ ๊ธธ์ด๊ฐ 3์ด ๋ ๋ ๊น์ง ๋ฐ๋ณตํด์ ๋ฌธ์์ด ์ถ๊ฐ
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] [Python] Level1_2016 (0) | 2022.03.07 |
---|---|
[Programmers] [Python] Level1_์ฒด์ก๋ณต (0) | 2022.03.06 |
[Programmers] [Python] Level1_๋ก๋์ ์ต๊ณ ์์์ ์ต์ ์์ (0) | 2022.02.26 |
[Programmers] [Python] Level1_์ต๋๊ณต์ฝ์์ ์ต์๊ณต๋ฐฐ์ (0) | 2022.02.25 |
[Programmers] [2022 kakao blind recruitment] [Python] Level1_์ ๊ณ ๊ฒฐ๊ณผ ๋ฐ๊ธฐ (0) | 2022.02.25 |