-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6814e07
commit 42f8af8
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,4 @@ def bfs(): | |
bfs() | ||
|
||
for i in range(2, n+1): | ||
print(visited[i]) | ||
print(visited[i]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
def solution(genres, plays): | ||
answer = [] | ||
dict = {} | ||
|
||
# 딕셔너리 만들기 | ||
for i in range(len(genres)): | ||
if genres[i] not in dict : | ||
dict[genres[i]] = [[plays[i], i]] | ||
else : | ||
dict[genres[i]].append([plays[i],i]) | ||
|
||
# 딕셔너리 안에 재생회수로 재정렬 | ||
for genres, plays in dict.items(): | ||
dict[genres] = sorted(plays, key=lambda x: x[0], reverse=True) | ||
|
||
# 각 장르 총합 계산 | ||
totals = {i: sum(j[0] for j in songs) for i, songs in dict.items()} | ||
|
||
# 총합 기준으로 딕셔너리 순서 변경 | ||
sorted_data = {k: v for k, v in sorted(dict.items(), key=lambda item: totals[item[0]], reverse=True)} | ||
|
||
|
||
# 정답 인덱스 추가 부분 | ||
for i in sorted_data.values(): | ||
answer.append(i[0][1]) | ||
if len(i) != 1: | ||
answer.append(i[1][1]) | ||
|
||
|
||
return answer |