2018년 카카오
def dart_game(data):
import re
units = re.match('([0-9]{1,2}[SDT][*#]?)([0-9]{1,2}[SDT][*#]?)([0-9]{1,2}[SDT][*#]?)', data).groups()
ans = []
for unit in units:
t = re.match('(\d{1,2})(\w)([*|#]?)', unit).groups()
score = int(t[0])
if t[1] == 'S':
score = score**1
elif t[1] == 'D':
score = score**2
elif t[1] == 'T':
score = score**3
if t[2] == '*':
score = score*2
try:
if ans[-1]:
ans[-1] = ans[-1]*2
except:
pass
elif t[2] == '#':
score = score*(-1)
ans.append(score)
return sum(ans)
2021년 카카오
def reco_name(new_id):
import re
one = new_id.lower()
two = re.sub('[^a-z0-9-_.]', '', one)
thr = re.sub('\.{2,}', '.', two)
fo = thr.strip('.')
if fo == '':
fiv = 'a'
else:
fiv =fo
if len(fiv) > 15:
six = re.match('.{15}', fiv).group().rstrip('.')
else:
six = fiv
seven = six
while len(seven) < 3:
seven = seven + seven[-1]
return seven