Programmers/프로그래머스-등수 매기기-python

cosmos·2022년 10월 23일
0
post-thumbnail
post-custom-banner

문제

코드

# https://school.programmers.co.kr/learn/courses/30/lessons/120882
# programmers, level0: 등수 매기기, python3
def solution(score: list) -> list:
    dict, avg_list = {}, [sum(num) / 2 for num in score]

    for index, avg in enumerate(sorted(avg_list, reverse=True), start=1):
        if avg not in dict:
            dict[avg] = index

    return [dict[avg] for avg in avg_list]

if __name__ == '__main__':
    print(solution([[80, 70], [90, 50], [40, 70], [50, 80]]))  # [1, 2, 4, 3]
    print(solution([[80, 70], [70, 80], [30, 50], [90, 100], [100, 90], [100, 100], [10, 30]]))  # [4, 4, 6, 2, 2, 1, 7]

결과

출처 & 깃허브

programmers 등수 매기기
github

post-custom-banner

0개의 댓글