동캄의 코딩도장

프로그래머스 level1 [추억 점수] 파이썬 본문

코테/프로그래머스

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

동 캄 2023. 4. 24. 23:09
#프로그래머스 level1 추억 점수
from collections import defaultdict
def solution(name, yearning, photo):
    answer = []
    dic=defaultdict(int)
    for i in range(len(name)):
        dic[name[i]]=yearning[i]
    for list_ in photo:
        cnt=0
        for name_ in list_:
            cnt+=dic[name_]
        answer.append(cnt)
    return answer

딕셔너리를 이용하였다.