프로그래머스/Lv. 1
12. 추억 점수
Seohyeong Lee
2024. 7. 12. 00:17
def solution(name, yearning, photo):
answer = []
yeardict = dict([[name[i], yearning[i]] for i in range(len(name))])
for ph in photo:
phans = 0
for people in ph:
if people in name:
phans += yeardict[people]
answer.append(phans)
return answer
유형 : 구현.
앞선 문제와 같이 dict 자료형을 이용해 풀이했다.
yeardict를 사용하여 쉽게 추억 점수를 찾을 수 있다.
단 dict에서 key 값이 존재하지 않는 경우에 대한 예외 처리에 유의