Created
February 25, 2019 07:02
-
-
Save 2minchul/e008ae96d1292c255774f014726dcc08 to your computer and use it in GitHub Desktop.
This file contains 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
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