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
'Algorithm > Programmers' 카테고리의 다른 글
Lv.1 공원 산책 (0) | 2023.11.05 |
---|---|
프로그래머스 Lv2. 호텔 대실 - 파이썬 (0) | 2023.08.12 |
Lv2. 과제 진행하기(Python) (0) | 2023.07.04 |
프로그래머스 괄호변환 - python (0) | 2021.03.13 |