728x90
320x100
def solution(genres, plays):
answer = []
total = {} # 장르 : 총재생횟수
genDic = {} # 장르 : (재생횟수, 고유넘버)
for i in range(len(genres)):
genre = genres[i]
play = plays[i]
if genres[i] in total.keys():
total[genres[i]] += plays[i]
genDic[genres[i]].append((plays[i],i))
else:
total[genres[i]] = plays[i]
genDic[genre] = [(play,i)]
# 가장 재생횟수가 높은 장르
total = sorted(total.items(), key=lambda x: x[1], reverse=True)
for key in total:
playlist = genDic[key[0]]
playlist = sorted(playlist, key=lambda x: x[0], reverse=True)
print(playlist)
for i in range(len(playlist)):
if i==2:
break
answer.append(playlist[i][1])
print(playlist)
return answer
728x90
320x100
'💻 하나씩 차곡차곡 > 프로그래머스 (Python)' 카테고리의 다른 글
[프로그래머스/Lv.1/Python] 기능개발 (0) | 2024.01.15 |
---|---|
[프로그래머스/Lv.1/Python] 같은 숫자는 싫어 (0) | 2024.01.12 |
[프로그래머스/Lv.1/Python] 폰켓몬 (0) | 2024.01.10 |
[프로그래머스/Lv.1/Python] 의상 (0) | 2024.01.09 |
[프로그래머스/Lv.2/Python] 전화번호 목록 (0) | 2024.01.08 |