Notice
Recent Posts
Recent Comments
Link
«   2026/07   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Be Data

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

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)

 

'IT > python' 카테고리의 다른 글

파이썬 Collections 모듈  (0) 2022.10.29
코테 보기 직전  (0) 2022.10.29
[파이썬 모듈] 리스트의 모든 조합 구하는 방법  (0) 2022.09.21
<문자열 처리> 관련 함수들 - python  (0) 2022.09.20
Comments