프로그래머스 - 베스트 앨범
문제집 링크 : http://aladin.kr/p/szPra
내일은 코딩테스트 with 파이썬
IT 취업을 준비하는 모든 수험생을 위해 쓰였다. 이 책의 문제들은 프로그래머스와 제휴하여 코딩 테스트에서 가장 많이 등장하는 자료구조와 이를 응용한 알고리즘을 사용하는 문제들로 엄선
www.aladin.co.kr
프로그래머스 URL :
[도서실습] 내일은 코딩테스트 with 파이썬(자료구조와 알고리즘의 기초부터 실전까지)
프로그래머스x김앤북 파이썬 코딩테스트 실습 강의 *본 강의는 <내일은 코딩테스트 with 파이썬(자료구조와 알고리즘의 기초부터 실전까지)> 내 실습을 바탕으로 제작된 무료 실습 강의입니다.
school.programmers.co.kr
■ 작성 코드
from collections import defaultdict
def solution(genres, plays):
check = defaultdict(list)
play_check = defaultdict(int)
for idx, (g, play) in enumerate(zip(genres, plays)):
check[g].append([idx, play])
play_check[g] += play
sorted_plays = sorted(play_check.items(), key=lambda x:-x[1])
answer = []
for g, _ in sorted_plays:
songs = sorted(check[g], key=lambda x: -x[1])[:2]
answer.extend([song for song, _ in songs])
return answer
반응형
'Programming Test > 문제풀이' 카테고리의 다른 글
[프로그래머스] 32. 중복된 문자 제거 - Python (0) | 2025.02.07 |
---|---|
[프로그래머스] 31. 외계어 사전 - Python (0) | 2025.02.07 |
[프로그래머스] 29. 의상 - Python (0) | 2025.02.05 |
[프로그래머스] 28. 전화번호 목록 - Python (0) | 2025.02.01 |
[프로그래머스] 27. 완주하지 못한 선수 - Python (0) | 2025.02.01 |