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
def solution(seoul):
return '๊น์๋ฐฉ์ {}์ ์๋ค'.format(seoul.index('Kim'))
๋ฌธ์์ด ๋ด๋ฆผ์ฐจ์์ผ๋ก ๋ฐฐ์นํ๊ธฐ
def solution(s):
return ''.join(sorted(s, reverse = True))
๋ฌธ์์ด ๋ด ๋ง์๋๋ก ์ ๋ ฌํ๊ธฐ
def solution(strings, n):
return sorted(sorted(strings), key = lambda x : x[n])
๋ฌธ์์ด ๋ด p์ y์ ๊ฐ์
def solution(s):
return s.lower().count('p') == s.lower().count('y')
์ํ์ ์ต๋ 10000 ๋ฌธ์ ๋ก ์ ํด์ ธ ์์ผ๋ฏ๋ก, ์ฐ๋ ํจํด์ 10000๊ฐ์ฉ ๋ง๋ค์ด์ฃผ๊ณ numpy ๋ฅผ ์ด์ฉํด ๊ฐ ํ์๋ณ๋ก ๋ง์ถ ๊ฐฏ์๋ฅผ {ํ์ : ์ ์} ํ์์ผ๋ก ๋ง๋ ํ, ๊ฐ์ฅ ๋ง์ด ๋ง์ถ ํ์์ ์ฐพ์ return ํด ์ฃผ๋๋ฐ ์ ๋ต์๊ฐ ์ฌ๋ฌ๋ช
์ผ ์ ์์ผ๋ ๊ฐ ํ์ ์ ์ max ๊ฐ๊ณผ ๋น๊ตํ์ฌ ์ ๋ต์ return ํฉ๋๋ค.
import numpy as np
def solution(answers):
n = len(answers)
students = {1 : np.array([1, 2, 3, 4, 5]*2000),
2 : np.array([2, 1, 2, 3, 2, 4, 2, 5]*1250),
3 : np.array([3, 3, 1, 1, 2, 2, 4, 4, 5, 5]*1000)}
answer = {}
for student, ans in students.items() :
answer[student] = sum(np.array(answers) == ans[:n])
return [x for x in [1, 2, 3] if answer[x] == max(answer.values())]