⭐ 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/160586
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
⭐ 풀이 코드
def solution(keymap, targets):
answer = []
keymaps = {}
for key in keymap:
for k in key:
if k not in keymaps:
keymaps[k] = key.index(k)+1
else:
if (key.index(k)+1) < keymaps[k]:
keymaps[k] = key.index(k)+1
for t in targets:
cnt = 0
try:
for c in t:
cnt += keymaps[c]
except:
cnt = -1
answer.append(cnt)
return answer
'Python > Programmers' 카테고리의 다른 글
[프로그래머스/Python] Lv 1. 공원산책 (2) | 2023.04.21 |
---|---|
[프로그래머스/Python] Lv 0. 로그인 성공? (0) | 2023.04.18 |
[프로그래머스/Python] Lv 2. 게임 맵 최단거리 (0) | 2023.04.18 |
[프로그래머스/Python] Lv 1. 체육복 (0) | 2023.04.17 |
[프로그래머스/Python] Lv 1. 신규 아이디 추천 (0) | 2023.04.17 |