문제 링크
1. 내 코드
'''
genres plays return
["classic", "pop", "classic", "classic", "pop"] [500, 600, 150, 800, 2500] [4, 1, 3, 0]
'''
'''
# name:value로 하면 중복으로 인해 가장 높은 value만 추출
# b = { name:value for name, value in zip(a, b) }
'''
def solution(genres, plays):
albums = []
initDict = {name: 0 for name, value in zip(genres, plays)}
max = 0
for i in range(len(genres)) :
initDict[genres[i]]+=plays[i]
manyPlaySort = sorted(initDict.items(), key = lambda x:x[1], reverse=True)
manyGenres = [(genres[i], plays[i]) for i in range(len(genres))]
manyGenresSort = sorted(manyGenres, key=lambda x: (x[0], -x[1]))
while manyPlaySort :
standard = manyPlaySort.pop(0)
for i in range(len(manyGenresSort)) :
if standard[0] == manyGenresSort[i][0] and max !=2 :
idx = plays.index(manyGenresSort[i][1])
albums.append(idx)
plays[idx] = 0
max+=1
max = 0
return albums
결과
평가
- print(solution(['A', 'A', 'B', 'A'], [2, 2, 2, 3]) )# [3, 0, 2]
- 위의 부분 안되는데 이건 A,B가 동시에 같은 값을 가지고 있을때 B로 가야하는데 A로 가서..
- 담에 고쳐야됨
git링크