IT/python

[프로그래머스 ]숫자 문자열과 영단어 : replace()

bs engineer 2022. 9. 14. 23:45

2021 카카오 채용연계형 인턴십 > 숫자 문자열과 영단어 문제

https://school.programmers.co.kr/learn/courses/30/lessons/81301

 

 

python의 "replace()"를 이용하면 정말 쉽다!

 

replace의 정말 간단한 예로는

a= "Hello, This is BS"

a.replace("Hello", "Hi")

이렇게 하면

"Hi, This is BS" 가 출력된다!

 

 

따라서, 

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

    for i in range(10):
        s=s.replace(en_list[i],str(i))
        
    return int(s)