https://school.programmers.co.kr/learn/courses/30/lessons/72410
def solution(new_id):
answer = ''
for letter in new_id.lower(): #1, 2단계
if letter.isalpha() or letter.isnumeric() or letter == '-' or letter == '_':
answer += letter
if letter == '.' and len(answer)!=0 and answer[-1]!='.': #3단계
answer += letter
print(answer)
if len(answer)!=0:
if answer[0]=='.': #4단계
answer = answer[1:]
if answer[-1]=='.':
answer=answer[:-1]
print(answer)
if answer == "": #5단계
answer += "a"
print(answer)
if len(answer) >= 16: # 6단계
answer = answer[0:15]
if answer[0]=='.': #4단계
answer = answer[1:]
if answer[-1]=='.':
answer=answer[:-1]
print(answer)
if len(answer) <=2 and len(answer)>0: #7단계
while len(answer)<3 :
answer += answer[-1]
print(answer)
return answer
이렇게 해서 맞긴 했는데 알고보니 정규표현식이라는 거 써서 해결하는 것임...^^
나만 어거지로 한거 아니겠ㅈㅣ
import re
def solution(new_id):
st = new_id
st = st.lower()
st = re.sub('[^a-z0-9\-_.]', '', st) #2단계
st = re.sub('\.+', '.', st) #3단계
st = re.sub('^[.]|[.]$', '', st) #4단계
st = 'a' if len(st) == 0 else st[:15] #5,6단계
st = re.sub('^[.]|[.]$', '', st) #6단계ㅖ
st = st if len(st) > 2 else st + "".join([st[-1] for i in range(3-len(st))]) #7단계
return st
외계어인가...