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

코린이·2022년 6월 5일
0

프로그래머스

목록 보기
13/22

📢 "숫자 문자열과 영단어" 문제

프로그래머스 문제 링크

🔎 풀이

사용언어 : python
replace를 사용하여 영단어를 해당하는 값으로 바꾸어줌
영단어와 num을 각각 list를 주어 반복문을 돌렸지만
다른 사람들은 dictionary를 사용하여 key, value로 해결

🔎 코드

def solution(s):
    num_string = ["one", "two", "three", "four",
                  "five", "six", "seven", "eight", "nine", "zero"]
    num = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]

    for x, y in zip(num_string, num):
            s = s.replace(x, y)
    answer = int(s)
    return answer
profile
초보 개발자

0개의 댓글