Algorithm/Programmers
Lv1.추억 점수
Himoonhee
2023. 11. 5. 14:33
728x90
https://school.programmers.co.kr/learn/courses/30/lessons/176963
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
def solution(name, yearning, photo):
answer = []
a_dict = {}
for i in range(len(name)):
a_dict[name[i]] = yearning[i]
for i in range(len(photo)):
sum_a = 0
for j in range(len(photo[i])):
if photo[i][j] in name:
sum_a += a_dict[photo[i][j]]
answer.append(sum_a)
return answer
-> 다른 사람의 풀이
def solution(이름, 점수, 사진):
return [sum(점수[이름.index(j)] for j in i if j in 이름) for i in 사진]
def solution(name, yearning, photo):
dictionary = dict(zip(name,yearning))
scores = []
for pt in photo:
score = 0
for p in pt:
if p in dictionary:
score += dictionary[p]
scores.append(score)
return scores
⭐️파이썬 dict, zip 함수를 사용하여 name과 yearning을 합쳐주기
그리고 꼭 i, j 숫자로 표현할 필요 x
728x90