[프로그래머스/Python]숫자 문자열과 영단어

Jimin_Note·2022년 5월 14일
0
post-thumbnail

💾숫자 문자열과 영단어

2021 카카오 채용연계형 인턴십

📍문제 설명
네오와 프로도가 숫자놀이를 하고 있습니다. 네오가 프로도에게 숫자를 건넬 때 일부 자릿수를 영단어로 바꾼 카드를 건네주면 프로도는 원래 숫자를 찾는 게임입니다.

📍입출력값

sresult
"one4seveneight"1478
"23four5six7"234567
"2three45sixseven"234567
"123"123

👉숫자는 숫자 그대로 출력, 영어는 숫자로 변경하여 출력

📍내 답안

def solution(s):
    answer = s 
    num_dict ={0:'zero',1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine'}
    
    for i in num_dict.items():
        answer = answer.replace(i[1], str(i[0]))   


    return int(answer)

🍰문자열 치환 replace 참고

profile
Hello. I'm jimin:)

0개의 댓글