새소식

Problem solving/문제 풀이 - 2023.01.26

[파이썬] 프로그래머스 개인정보 수집 유효기간 풀이

  • -

문제 확인

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

나의 풀이

  • 날짜 정보를 간단하게 처리하기 위해서 '일' 단위로 변경하여 문제를 풀었다.
  • 2 중 리스트를 zip하기 위해서 *를 사용했다.
def cnt_day(day: str) -> int:
    # 날짜 정보를 '일' 단위로 변경하는 함수
    day = day.split(".")
    day = int(day[0]) * 12 * 28 + int(day[1]) * 28 + int(day[2])
    return day

def solution(today, terms, privacies):
    answer = []
    # 비교하기 쉽게 '일' 단위로 변경
    today = cnt_day(today)
    # key : term, value : 기간
    terms = [term.split(" ") for term in terms]
    terms = dict(zip(list(zip(*terms))[0], list(zip(*terms))[1]))
    for idx, privacy in enumerate(privacies):
        # 날짜, 약관 분리
        day, term = privacy.split(" ")
        day = cnt_day(day)
        day += (int(terms[term]) * 28)
        # 제거할 날짜 정보
        if today >= day:
            answer.append(idx + 1)
    return answer

 


참고

 

How to zip lists in a list

I want to zip the following list of lists: >>> zip([[1,2], [3,4], [5,6]]) [[1,3,5], [2,4,6]] This could be achieved with the current zip implementation only if the list is split into

stackoverflow.com

 

Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.