로또 우선 순위

박진은·2023년 3월 8일
0

코테

목록 보기
11/44

https://school.programmers.co.kr/learn/courses/30/lessons/77484
문제는 위에서 확인할 수 있다.

def solution(lottos, win_nums):
    # lottos 내가 뽑은 숫자
    # win_nums 1등 숫자
    match_num = 0
    new_lottos = []
    zero = 0


    for i in range(len(lottos)):
        if lottos[i] != 0:
            new_lottos.append(lottos[i])

    zero = len(lottos) - len(new_lottos)

    for i in new_lottos:
        if i in win_nums:
            match_num += 1

    won_dict = {7-x : x for x in range(1,7)}
    won_dict[0] = 6
    answer = [won_dict[match_num+zero],won_dict[match_num]]


    return answer

순서에 상관없이 매치되는 번호를 기준으로 순위를 정하는 과정이기 때문에 파이선 in 연산자를 사용해서 구현했다. 만일 c언어 였다면 너무 힘들었을거 같다. won_dict[0] = 6 매치되는 숫자가 하나도 존재하지 않을 때도 숫자가 올라가야하기 때문에 0을 추가해주지 않아서 오류가 발생했었다

profile
코딩

0개의 댓글