[Programmers] 숫자 문자열과 영단어 - python
프로그래머스 숫자 문자열과 영단어 문제이다. 영어를 숫자로 변환하는 문제이다. ex) seven3two4 -> 7324 def solution(s): dict = {"zero":0,"one":1,"two":2,"three":3,"four":4,"five":5,"six":6,"seven":7, "eight":8,"nine":9,"ten":10} for i in dict: if i in s: s = s.replace(i, str(dict[i])) answer = int(s) return answer 가장 먼저 생각나는대로 단순히 딕셔너리를 만들어 풀었다. 딕셔너리를 모두 돌면서 숫자가 영어로 쓰였으면, 숫자로 바꾸도록 했는데 그럴 필요가 없었다. 영어로 쓰였는지 판별하는 부분이 없었어도 됐다. for i i..
2022. 6. 29.