[프로그래머스/파이썬]베스트 앨범

김진만·2022년 10월 18일
0

코딩테스트

목록 보기
3/10

def solution(genres, plays):
answer = []
a={}
b={}
for i,(g,p) in enumerate(zip(genres,plays)):
if g not in a:
a[g]=[(i,p)]
else:
a[g].append((i,p))

    if g not in b:
        b[g]=p
    else:
        b[g]+=p
for (k,v) in sorted(b.items(),key=lambda x:x[1],reverse=True):
    for (i,p) in sorted(a[k],key=lambda x:x[1], reverse=True)[:2]:
        answer.append(i)
return answer

genres=["classic", "pop", "classic", "classic", "pop"]
plays=[500, 600, 150, 800, 2500]
print(solution(genres,plays))

profile
충분한 전기와 컴퓨터 한 대와 내 이 몸만 남아 있다면 지구를 재건할 수 있습니다.

0개의 댓글