Programmers/프로그래머스-숫자 문자열과 영단어-python

cosmos·2022년 3월 17일
0
post-thumbnail

문제

풀이

  • replacedict을 활용하면 쉽게 구현할 수 있다.

코드

# https://programmers.co.kr/learn/courses/30/lessons/81301
# programmers, level1: 숫자 문자열과 영단어, python3
# 2021 카카오 채용연계형 인턴쉽
def solution(s):
    dict = {
        'zero': '0', 'one': '1', 'two': '2', 'three': '3', 'four': '4',
        'five': '5', 'six': '6', 'seven': '7', 'eight': '8', 'nine': '9'
    }

    for k, v in dict.items():
        s = s.replace(k, v)

    return int(s)

결과


출처 & 깃허브

프로그래머스 숫자 문자열과 영단어
github

0개의 댓글