728x90
https://programmers.co.kr/learn/courses/30/lessons/72410
이것이 바로 구현..!
문제에 나와있는 조건들 그대로 다 구현하면 된다.
풀다보면 재밌다.
코드 :
def solution(new_id):
answer = ''
# 1
new_id = new_id.lower()
# 2
for c in new_id :
if c.isalpha() or c.isdigit() or c in ['-','_','.'] :
answer+=c
# 3
while '..' in answer :
answer = answer.replace('..','.')
# 4
answer=answer.strip('.') # 양 끝의 '.'제거
# 5
if answer == '' :
answer = 'a'
# 6
if len(answer) > 15 :
answer = answer[:15]
if answer[-1]=='.' :
answer = answer[:-1]
# 7
while len(answer) < 3 :
answer+= answer[-1]
return answer
주의할 점은 처리를 하고 다시 answer에 넣어주어야 한다는 것이다.
참고 블로그 :
복습 :
✅ 20220629
✅ 20220630
반응형
'알고리즘 > 프로그래머스문제풀이' 카테고리의 다른 글
[Python/프로그래머스]오픈채팅방 (0) | 2022.06.28 |
---|---|
[Python/프로그래머스]문자열 압축 (0) | 2022.06.28 |
[Python/프로그래머스]신고 결과 받기 (0) | 2022.06.28 |
[Python/프로그래머스]순위_그래프 (0) | 2022.06.19 |
[Python/프로그래머스] 소수 찾기_완탐 (0) | 2022.06.19 |