숫자 문자열과 영단어

발자·2022년 9월 7일
0

programmers

목록 보기
7/34

python

def solution(s):
    textList = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    for i in range(0, len(textList)) :
        s = s.replace(textList[i], str(i))
    answer = int(s)
    return answer

🧩 replace()

dictionary로 해도 깔끔하다.
replace는 한 번에 일치하는 모든 값을 바꿔준다.

0개의 댓글