Created
January 3, 2020 14:36
-
-
Save ShinJJang/196a5d0287f00c37ed6ed2e9063ceb55 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(genres, plays): | |
g_count = {} | |
g_list = {} | |
for idx in range(len(genres)): | |
g = genres[idx] | |
g_count[g] = g_count.get(g, 0) + plays[idx] | |
sg_list = g_list.get(g, []) | |
sg_list.append((idx, plays[idx])) | |
g_list[g] = sg_list | |
g_order = sorted(g_count.items(), key=lambda x: x[1]) | |
g_order.reverse() | |
g_order = [g[0] for g in g_order] | |
answer = [] | |
for g in g_order: | |
temp = sorted(g_list[g], key=lambda x: (x[1], -x[0])) | |
temp.reverse() | |
temp = [x[0] for x in temp][:2] | |
answer += temp | |
return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment