[프로그래머스/카카오 81301] 숫자 문자열과 영단어 (Python)
문제 링크 #
개요 #
- 딕셔너리를 사용해 해결할 수 있는 문제다.
문제 조건 #
- 일부 숫자가 영단어로 변환된 문자열을 원래의 숫자로 되돌려 반환하는 문제다.
문제 해설 #
- 각각의 영단어에 대한 숫자 맵과 문자열의
replace함수를 사용하면 쉽게 해결할 수 있다.
해설 코드 #
python
def solution(s):
answer = s
word_dict = {'zero':'0','one':'1','two':'2','three':'3',
'four':'4','five':'5','six':'6','seven':'7',
'eight':'8','nine':'9'}
for key, value in word_dict.items():
answer = answer.replace(key, value)
return int(answer)