로또의 최고 순위와 최저 순위_프로그래머스_파이썬

  • 나의 풀이
def solution(lottos, win_nums):
    count , rank = 0, 0
    for i in lottos:
        if i in win_nums:
            rank+=1
        if i ==0:
            count+=1
    if count == 6:
        return [1,6]
    if rank == 0 and count == 0:
        return [6, 6]
    
    return [7-rank-count,7-rank]
print(solution([0, 0, 0, 0, 0, 0],[38, 19, 20, 40, 15, 25]))
[1, 6]
  • 다른 사람 풀이
def solution(lottos, win_nums):
    count = lottos.count(0)
    rank = [6,6,5,4,3,2,1]
    ans = 0 
    for i in lottos:
        if i in win_nums:
            ans+=1
    return [rank[count + ans],rank[ans]]
print(solution([0, 0, 0, 0, 0, 0],[38, 19, 20, 40, 15, 25]))
[1, 6]

Comments