🚩 문제 주소
(2021년 12월 31일에 푼 문제입니다.)
📄 접근 방법
딕셔너리
더보기
- 딕셔너리를 먼저 만들어 줍니다.
- 숫자를 발견하면 answer에 저장합니다.
- 아니라면 temp에 하나씩 저장합니다.
3-1. 저장하다가 딕셔너리의 key와 같아지면 value를 answer에 저장하고 temp를 초기화합니다. - answer를 int로 변환한 뒤 출력합니다.
👨💻 나의 코드
def solution(s):
temp = ''
answer = ''
dic = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
for i in s:
if i.isnumeric():
answer += i
else:
temp += i
if temp in dic.keys():
answer += str(dic[temp])
temp = ''
return int(answer)
'Problem Solving > Programmers' 카테고리의 다른 글
[프로그래머스 / JS] 구명보트 - Level 2 (0) | 2023.03.24 |
---|---|
[프로그래머스 / Python, JS] 키패드 누르기 - Level 1 (0) | 2023.03.22 |
[프로그래머스 / Python] 다트 게임 - Level 1 (0) | 2023.03.22 |
[프로그래머스 / Python] 비밀지도 - Level 1 (0) | 2023.03.22 |
[프로그래머스 / Python] 크레인 인형뽑기 게임 - Level 1 (0) | 2023.03.22 |