링크
내 풀이(O)
- 약관의 유효기간(terms)를 dictionary로 만든다 =>
terms_dict
- relativedelta 라이브러리를 사용해서 만료일을 구한다 =>
expiration_date
from datetime import datetime
from dateutil.relativedelta import relativedelta
def solution(today, terms, privacies):
answer = []
terms_dict = { t.split(' ')[0]: int(t.split(' ')[1]) for t in terms }
for i, p in enumerate(privacies):
[d, t] = p.split(' ')
expiration_date = datetime.strptime(d, "%Y.%m.%d") + relativedelta(months=terms_dict[t], days=-1)
if expiration_date < datetime.strptime(today, "%Y.%m.%d"):
answer.append(i + 1)
return answer
검증용 코드
today = ["2022.05.19", "2020.01.01"]
terms = [["A 6", "B 12", "C 3"], ["Z 3", "D 5"]]
privacies = [["2021.05.02 A", "2021.07.01 B", "2022.02.19 C", "2022.02.20 C"], ["2019.01.01 D", "2019.11.15 Z", "2019.08.02 D", "2019.07.01 D", "2018.12.28 Z"]]
result = [[1, 3], [1, 4, 5]]
for idx in range(len(result)):
print(idx, '성공' if solution(today[idx], terms[idx], privacies[idx]) == result[idx] else "실패")