알고리즘

[프로그래머스, 파이썬] 추억 점수

hminor 2024. 3. 13. 09:54

풀이

  • 간단하게 이름과 점수를 딕셔너리로 묶고
  • result를 photo 크기 만큼 만들어서 
  • 반복문을 활용하여 문제를 간단하게 해결

 

def solution(name, yearning, photo):
    dic = {name[i]:yearning[i] for i in range(len(name))}
    result = [0]*len(photo)
    for i,p in enumerate(photo):
        for idx,j in enumerate(p):
            if dic.get(j): result[i] += dic[j]
    return result