-
Notifications
You must be signed in to change notification settings - Fork 0
/
id_recommend.py
110 lines (87 loc) · 2.41 KB
/
id_recommend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""
첫 번째 풀이에는 함수를 모두 구현하였음에도 중구난방식이라 어디가 어느 기능을 담당하는지 한눈에 보기 힘들었다. 하지만 각각의 기능을 모두 함수로 바꿔 표현하니
훨씬 간단해 보이는 것을 느꼈다.
"""
'''
첫번째 풀이
'''
def recom(new_id):
#1
new_id = new_id.lower()
#2
for i in new_id:
if i.islower() == False and i != '-' and i != '_' and i != '.' and i.isnumeric() == False:
new_id = new_id.replace(i,'')
#3
while '..' in new_id:
new_id = new_id.replace('..','.')
#4
if new_id.startswith('.') == True:
new_id = new_id[1:]
if new_id.endswith('.') == True:
new_id = new_id[:len(new_id)-1]
#5
if new_id == "":
new_id += "a"
#6
if len(new_id) >= 16:
new_id = new_id[:15]
if new_id.endswith('.') == True:
new_id =new_id[:len(new_id)-1]
#7
if len(new_id) <= 2:
new_id = new_id + new_id[-1]*(3-len(new_id))
return new_id
def solution(new_id):
answer = new_id
if len(new_id) < 3 or len(new_id) > 15:
return recom(new_id)
for i in new_id:
if i.islower() == False and i != '-' and i != '_' and i != '.' and i.isnumeric() == False:
return recom(new_id)
if new_id[0] == '.' or new_id[-1] == '.' or '..' in new_id:
return recom(new_id)
return answer
'''
두번째 풀이
'''
def first(new_id):
return new_id.lower()
def second(new_id):
sc = ['-', '_', '.']
str_temp = ''
for char in new_id[:]:
if char.islower() or char.isdigit() or char in sc:
str_temp += char
return str_temp
def third(new_id):
while '..' in new_id:
new_id = new_id.replace("..", ".")
return new_id
def fourth(new_id):
return new_id.strip('.')
def fifth(new_id):
if not new_id:
return 'a'
else:
return new_id
def sixth(new_id):
if len(new_id) >= 16:
return new_id[:15].strip('.')
else:
return new_id
def seventh(new_id):
while len(new_id) <= 2:
new_id += new_id[-1]
return new_id
def solution(new_id):
answer = ''
new_id = first(new_id)
new_id = second(new_id)
new_id = third(new_id)
new_id = fourth(new_id)
new_id = fifth(new_id)
new_id = sixth(new_id)
new_id = seventh(new_id)
answer = new_id
return answer