https://programmers.co.kr/learn/courses/30/lessons/42889?language=python3
νμ΄
μ²μ λ΄κ° νΌ νμ΄μ΄λ€. λμ λ리λ₯Ό μ΄μ©νμ¬ νλ €κ³ νμ§λ§ μκ°λ³΅μ‘λκ° λμμ μΈμ§ 70.4 μ μ λ°κ² λμλ€.
# νλ‘κ·Έλλ¨Έμ€ 1λ¨κ³ - μ€ν¨μ¨
from collections import defaultdict
n = int(input()) # μ€ν¨μ¨
stages = list(map(float, input().split())) # stages
def solution(n, stages):
answer = []
dictionary = defaultdict(float)
res_dict = defaultdict(float)
a = len(stages)
for i in range(1, n+1):
dictionary[i] = stages.count(i)
res_dict[i] = stages.count(i)
for i in range(1, n+1):
res_dict[i] = dictionary[i] / a
a = a - dictionary[i]
new_dict = sorted(res_dict.items(),reverse=True, key = lambda x: x[1])
for key in new_dict:
answer.append(key[0])
return answer
print(solution(n, stages))
λ§λ νμ΄
def solution(N, stages):
answer = []
score = []
R = len(stages)
for i in range(1, N + 1):
if R != 0:
count = stages.count(i)
score.append((i, count / R))
R -= count
else:
score.append((i, 0))
score = sorted(score, key=lambda x: (-x[1], x[0]))
for i in range(len(score)):
answer.append(score[i][0])
return answer