🔅코딩테스트 공부🔅/❗프로그래머스(Lv.1)
[프로그래머스] Level1 로또의 최고 순위와 최저 순위(python)
윤무무
2023. 2. 13. 16:39
https://school.programmers.co.kr/learn/courses/30/lessons/77484
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1. 내가 작성한 코드
def solution(lottos, win_nums):
lank = {0:6,1:6,2:5,3:4,4:3,5:2,6:1}
cnt = 0
answer = []
for i in lottos:
print(i)
if i in win_nums:
cnt += 1
answer.append(lank[cnt + lottos.count(0)])
answer.append(lank[cnt])
return answer
딕셔너리와 count 함수를 이용해서 풀었다.
return 해야하는 것이 2개 이상이면 배열을 사용해야 하는 줄 알았는데
return lank[cnt + lottos.count(0)],lank[cnt] 을 해도 알아서 묶여 나가는 걸 첨 알았다.
2. 수정 코드
def solution(lottos, win_nums):
lank = {0:6,1:6,2:5,3:4,4:3,5:2,6:1}
cnt = 0
for i in lottos:
print(i)
if i in win_nums:
cnt += 1
return lank[cnt + lottos.count(0)],lank[cnt]