728x90
320x100
def solution(s):
english = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
answer = 0
for i, v in enumerate(english) :
s = s.replace(english[i], number[i])
return int(s)
(+) 다른 사람 풀이
num_dic = {"zero":"0", "one":"1", "two":"2", "three":"3", "four":"4", "five":"5", "six":"6", "seven":"7", "eight":"8", "nine":"9"}
def solution(s):
answer = s
for key, value in num_dic.items():
answer = answer.replace(key, value)
return int(answer)
dic을 사용해서 꺼내서 바로 바꿀수도 있움.
728x90
320x100
'💻 하나씩 차곡차곡 > 프로그래머스 (Python)' 카테고리의 다른 글
[프로그래머스/python/Lv1] 두 개 뽑아서 더하기 (0) | 2023.12.22 |
---|---|
[프로그래머스/python/Lv1] [1차] 비밀지도 (0) | 2023.12.21 |
[프로그래머스/python/Lv1] 예산 (0) | 2023.12.19 |
[프로그래머스/python/Lv1] 3진법 뒤집기 (0) | 2023.12.18 |
[프로그래머스/python/Lv1] 부족한 금액 계산하기 (0) | 2023.12.17 |