목록2024/08/22 (1)
on my way
[프로그래머스 코딩테스트 연습] 로또의 최고 순위와 최저 순위 (Python3) Lv1
def solution(lottos, win_nums): cnt0 = lottos.count(0) cntw = 0 for w in win_nums: if w in lottos: cntw += 1 scores = {6: 1, 5: 2, 4: 3, 3: 4, 2: 5, 1: 6, 0: 6} return scores[cntw + cnt0], scores[cntw] 처음에는 7 - 일치 횟수 이런식으로 풀어서 코드가 더러워진 감이 있었다.깔끔하게 정리하기 위해 딕셔너리를 사용해서 일치 횟수와 매칭시켜 출력하게끔 했다. 코드 해설cnt0 계산:cnt0 = lottos.count(0)는 민우가 모르는 번호 0의 개수를 계산cntw 계산:cntw는 민우가..
algorithm/Python
2024. 8. 22. 03:57