Programmers

[프로그래머스 / 파이썬 풀이] 실패율

Hoo_Dev 2023. 1. 27. 11:20

def solution(N, stages):
    answer = []
    ans_lst = []
    stages = sorted(stages)
    
    for stage in range(1, N+1):
        cnt = stages.count(stage)
        if len(stages) != 0:
            ans_lst.append([cnt/len(stages), stage])
            for i in range(cnt):
                stages.pop(0)
        else:
            ans_lst.append([0, stage])
            
        ans_lst.sort(key = lambda x : (-x[0], x[1]))
                    
    for i in ans_lst:
        answer.append(i[1])
        
    return answer

key lambda 를 사용한 sort 풀이.

zero division 에러를 생각하고 풀이해야한다.