해시 - 베스트 앨범 / 파이썬
def solution(genres, plays): dic, hap = {}, {} i = 0 for g, p in zip(genres, plays): if g not in dic: dic[g] = [[p, i]] hap[g] = p else: dic[g].append([p, i]) hap[g] += p i += 1 s_hap = sorted(hap.items(), key=lambda x: x[1], reverse=True) ret = [] for k, _ in s_hap: lst = sorted(dic[k], key=lambda x: x[0], reverse=True) if len(lst) > 2: lst = lst[:2] for _, num in lst: ret.append(num) return re..