Skip to content

Instantly share code, notes, and snippets.

@hongdonghyun
Last active February 26, 2019 04:09
Show Gist options
  • Save hongdonghyun/60c6a161929001117e24cae6af23875d to your computer and use it in GitHub Desktop.
Save hongdonghyun/60c6a161929001117e24cae6af23875d to your computer and use it in GitHub Desktop.
from collections import defaultdict
def solution(genres, plays):
answer = []
new_genres = defaultdict(int)
new_play = defaultdict(list)
for index,(k,v) in enumerate(zip(genres,plays)):
new_genres[k] += v
new_play[k].append((index,-v))
new_order = sorted(new_genres.keys(),key=lambda k : new_genres[k],reverse=True)
for i in new_order:
answer.extend([pk for pk,value in sorted(new_play[i],key=lambda t : t[1])[:2]])
return answer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment