def solution(s, n):
s = list(s)
for i in range(len(s)):
if s[i].isupper():
s[i]=chr((ord(s[i])-ord('A')+ n)%26+ord('A'))
elif s[i].islower():
s[i]=chr((ord(s[i])-ord('a')+ n)%26+ord('a'))
return "".join(s)
import re
def solution(n, arr1, arr2):
# ๊ฐ ๋ฐฐ์ด์ ์์๋ค์ ์ด์ง์๋ก ๋ณํํ๊ณ , OR ์ฐ์ฐ.
map_ = [bin(x | y)[2:].zfill(n) for x, y in zip(arr1, arr2)] # bin ํจ์๋ ์ด์ง์ ์์ '0b'๋ฅผ ๋ถ์ฌ์ ๋ฐํํ๋ฏ๋ก [2:]๋ฅผ ์ฌ์ฉํ์ฌ ์ด ๋ถ๋ถ์ ์ ๊ฑฐ
answer = []
for i in map_ :
tmp = re.sub('1', '#', i)
tmp = re.sub('0', ' ', tmp)
answer.append(tmp)
return answer
import re
def solution(dartResult):
bonus = {'S': 1, 'D': 2, 'T': 3} # ๋ณด๋์ค์ ๋ฐ๋ฅธ ์ ๊ณฑ ์ง์
option = {'': 1, '*': 2, '#': -1} # ์ต์
์ ๋ฐ๋ฅธ ์ ์ ๋ฐฐ์
p = re.compile('(\d+)([SDT])([*#]?)') # ์ ๊ท์ ํจํด ์ ์
dart = p.findall(dartResult) # ์ ๊ท์์ ์ฌ์ฉํด ์ ์, ๋ณด๋์ค, ์ต์
์ถ์ถ
for i in range(len(dart)):
if dart[i][2] == '*' and i > 0:
dart[i-1] *= 2 # ์ด์ ์ ์์ ์คํ์(*) ํจ๊ณผ ์ ์ฉ
# ํ์ฌ ์ ์ ๊ณ์ฐ
dart[i] = int(dart[i][0]) ** bonus[dart[i][1]] * option[dart[i][2]]
answer = sum(dart)
return answer
ํฌ๋ ์ธ ์ธํ๋ฝ๊ธฐ ๊ฒ์ ๋ฐ๋ก๊ฐ๊ธฐ
def solution(board, moves):
bucket = []
answer = 0
for index in [m-1 for m in moves] :
column = [x[index] for x in board]
for i, doll in enumerate(column) :
if doll == 0: continue
if bucket[-1:] == [doll]:
bucket.pop()
answer += 2
else:
bucket.append(doll)
board[i][index] = 0
break
return answer
from collections import Counter
def solution(participant, completion):
answer = Counter(participant) - Counter(completion)
return list(answer.keys())[0]
์ ๊ท ์์ด๋ ์ถ์ฒ ๋ฐ๋ก๊ฐ๊ธฐ
import re
def solution(new_id):
st = new_id
st = st.lower()
st = re.sub('[^a-z0-9\-_.]', '', st)
st = re.sub('\.+', '.', st)
st = re.sub('^[.]|[.]$', '', st)
st = 'a' if len(st) == 0 else st[:15]
st = re.sub('^[.]|[.]$', '', st)
st = st if len(st) > 2 else st + "".join([st[-1] for i in range(3-len(st))])
return st