출처: 프로그래머스
def solution(lottos, win_nums):
answer = [0,0]#결과 저장
num=[6,6,5,4,3,2,1]#6등 이하~1등 순서
cnt=0
zero=lottos.count(0)
for i in lottos:
if i in win_nums:
cnt+=1
answer[0]=num[zero+cnt]#최대값
answer[1]=num[cnt]#최소값
return answer
lottos=list(map(int,input().split()))
win_nums=list(map(int,input().split()))
print(solution(lottos,win_nums))
접근 방법
처음에는 반복문을 하나 더 두어 lottos의 0의 개수를 세서 풀었다. 그러나 다른 분의 풀이를 확인하게 되었고 위와같은 코드로 수정 후 제출하게 되었다.
count()함수를 사용한 게 인상깊었다.