Skip to content

Instantly share code, notes, and snippets.

@2minchul
Created February 25, 2019 07:02
Show Gist options
  • Save 2minchul/e008ae96d1292c255774f014726dcc08 to your computer and use it in GitHub Desktop.
Save 2minchul/e008ae96d1292c255774f014726dcc08 to your computer and use it in GitHub Desktop.
from collections import Counter, defaultdict
def solution(genres, plays):
song_limit = 2
answer = []
songs = defaultdict(dict)
_genre_counter_dict = defaultdict(int)
for i, (genre, play_cnt) in enumerate(zip(genres, plays)):
_genre_counter_dict[genre] += play_cnt
songs[genre][i] = play_cnt
genre_counter = Counter(_genre_counter_dict)
for genre, _ in genre_counter.most_common():
for i, __ in Counter(songs[genre]).most_common(song_limit):
answer.append(i)
return answer
if __name__ == '__main__':
args = ["classic", "pop", "classic", "classic", "pop"], [500, 600, 150, 800, 2500]
print(solution(*args))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment