문제 링크 : https://programmers.co.kr/learn/courses/30/lessons/72410
def solution(new_id):
answer = '' lowerLine = new_id.lower()
for i in lowerLine: if i.isalpha() or i.isdigit() or i in ['-', '_', '.']: answer += i
while '..' in answer: answer = answer.replace('..', '.')
if len(answer) > 1: if answer[0] == '.': answer = answer[1:] elif len(answer) == 1 and answer[0] == '.': answer = ''
if len(answer) > 1: if answer[-1] == '.': answer = answer[:-1] elif len(answer) == 1 and answer[-1] == '.': answer = ''
if len(answer) == 0: answer += 'a'
if len(answer) > 15: answer = answer[:15] if answer[-1] == '.': answer = answer[:-1]
while len(answer) <= 2: answer += answer[-1]
return answer
|