프로그래머스 - LV.0 - 숫자 문자열과 영단어

박종일·2023년 7월 24일
0

프로그래머스 LV.0

목록 보기
24/46



나의 풀이

num_dic = {"zero":"0", "one":"1", "two":"2", "three":"3", "four":"4", "five":"5", "six":"6", "seven":"7", "eight":"8", "nine":"9"}

def solution(s):
    answer = s
    for key, value in num_dic.items():
        answer = answer.replace(key, value)
    return int(answer)

다른 풀이

def solution(s):
    words = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']

    for i in range(len(words)):
        s = s.replace(words[i], str(i))

    return int(s)

딕셔너리, 리스트 등의 자료구조로 해결할 수 있는 방법이 많다.
더불어, 튜플 등 파이썬 기본 자료구조에 대해 자세히 알고 있어야한다!

profile
존경하는 인물: 스토브리그 백승수 단장(남궁민)

0개의 댓글