본문 바로가기
알고리즘/소스코드

PROGRAMMERS 42579: 베스트앨범

by cjw.git 2021. 1. 5.

Link : programmers.co.kr/learn/courses/30/lessons/42579


Python

더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def solution(genres, plays):
    answer = []
    ranking_kind = dict()
    play = dict()
    for idx, key in enumerate(genres):
        if key not in play:
            play[key] = list()
            ranking_kind[key] = 0
        ranking_kind[key] += plays[idx]
        play[key].append((plays[idx], idx))
 
    for i in play:
        play[i].sort(key=lambda x: x[0], reverse=True)
    ranking_kind = [[i, ranking_kind[i]] for i in ranking_kind]
    ranking_kind.sort(key=lambda x: x[1], reverse=True)
 
    for i in ranking_kind:
        for repeat in range(2):
            try:
                answer.append(play[i[0]][repeat][1])
            except Exception:
                pass
    return answer
cs

FeedBack

  1.  

 

 

 

cjw.git@gmail.com

'알고리즘 > 소스코드' 카테고리의 다른 글

PROGRAMMERS 42586: 기능개발  (0) 2021.01.05
PROGRAMMERS 42584: 주식가격  (0) 2021.01.05
PROGRAMMERS 42578: 위장  (0) 2021.01.05
PROGRAMMERS 42839: 소수 찾기  (0) 2021.01.02
KOREATECH 1008: 순환 소수  (0) 2021.01.02

댓글