[프로그래머스] 숫자 문자열과 영단어Lv.1 - Python

GoshK·2022년 1월 31일
0

[프로그래머스] Python

목록 보기
46/68
post-thumbnail

[프로그래머스] 숫자 문자열과 영단어Lv.1

나의 풀이

def solution(s):
    english = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    for i in range(len(english)):
        s = s.replace(english[i], str(i))
    return int(s)
  • 각 숫자에 맞는 영문자 리스트를 만들어 주고, 리스트를 돌면서 입력 문자에서 일치하는 문자를 바꿔주고 정수형으로 리턴한다.

0개의 댓글