forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.py
More file actions
25 lines (20 loc) · 763 Bytes
/
3.py
File metadata and controls
25 lines (20 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def solution(N, stages):
answer = []
length = len(stages)
# 스테이지 번호를 1부터 N까지 증가시키며
for i in range(1, N + 1):
# 해당 스테이지에 머물러 있는 사람의 수 계산
count = stages.count(i)
# 실패율 계산
if length == 0:
fail = 0
else:
fail = count / length
# 리스트에 (스테이지 번호, 실패율) 원소 삽입
answer.append((i, fail))
length -= count
# 실패율을 기준으로 각 스테이지를 내림차순 정렬
answer = sorted(answer, key=lambda t: t[1], reverse=True)
# 정렬된 스테이지 번호 반환
answer = [i[0] for i in answer]
return answer