문제링크: 개인정보 수집 유효기간
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️⭐️⭐️ |
| 풀이시간 | 35분 |
| 제출횟수 | 5 |
| 인터넷검색유무 | yes |
🍒 My Code
def solution(today, terms, privacies):
answer = []
term = {}
for t in terms:
term[t.split()[0]]=t.split()[1]
for idx, p in enumerate(privacies):
date,types = p.split()[0],p.split()[1]
year,month,day = int(date.split(".")[0]),int(date.split(".")[1]),int(date.split(".")[2])
month = month+int(term[types])
if month>12:
year+=month//12
month-=(month//12)*12
day-=1
if day==0:
day = 28
month-=1
if month==0:
month = 12
year-=1
#print(year,month,day)
if int(today.split(".")[0])>year:
answer.append(idx+1)
elif int(today.split(".")[0])==year:
if int(today.split(".")[1])>month:
answer.append(idx+1)
elif int(today.split(".")[1])==month:
if int(today.split(".")[2])>day:
answer.append(idx+1)
return answer
💡 What I learned
def to_days(date):
year, month, day = map(int, date.split("."))
return year * 28 * 12 + month * 28 + day
map(function, iterable) : 리스트의 요소를 지정된 함수로 처리해주는 함수(원본 리스트를 변경하지 않고 새 리스트를 생성).
두 번째 인자로 들어온 반복 가능한 자료형 (리스트나 튜플)을 첫 번째 인자로 들어온 함수에 하나씩 집어넣어서 함수를 수행하는 함수임.
즉, map(적용시킬 함수, 적용할 값들)로 생각할 수 있음.
다만, map 함수의 반환 값은 map객체 이기 때문에 해당 자료형을 list 혹은 tuple로 형 변환시켜주어야 함
- iterable: 반복 가능한 자료형(리스트, 튜플 등)
- list(map(함수, 리스트))
- tuple(map(함수, 튜플))
a = list(map(str, range(10)))
>> a = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']