참고
,참고1
1. 구현
정해
def solution(new_id):
new_id = new_id.lower()
answer = ''
for word in new_id:
if word.isalnum() or word in '-_.':
answer += word
while '..' in answer:
answer = answer.replace('..', '.')
answer = answer[1:] if answer[0] == '.' and len(answer) > 1 else answer
answer = answer[:-1] if answer[-1] == '.' else answer
answer = 'a' if answer == '' else answer
if len(answer) >= 16:
answer = answer[:15]
if answer[-1] == '.':
answer = answer[:-1]
if len(answer) <= 3:
answer = answer + answer[-1] * (3-len(answer))
return answer
80점
import re
def solution(new_id):
id = new_id.lower()
id = re.sub(r"[^a-zA-Z0-9._-]","",id)
if "." in id:
id = re.sub(r"\.+",".",id)
if id[0] == ".":
id = id[1:]
elif id[-1] == ".":
id = id[:-1]
if len(id) == 0:
id = id + "a"
elif len(id) >= 16:
id = id[:15]
if id[-1] == ".":
id = id[:-1]
if len(id) <= 2:
last = id[-1]
while len(id) < 3:
id += last
return id