https://programmers.co.kr/learn/courses/30/lessons/81301
def solution(s):
answer = s
answer = answer.replace('zero', '0')
answer = answer.replace('one', '1')
answer = answer.replace('two', '2')
answer = answer.replace('three', '3')
answer = answer.replace('four', '4')
answer = answer.replace('five', '5')
answer = answer.replace('six', '6')
answer = answer.replace('seven', '7')
answer = answer.replace('eight', '8')
answer = answer.replace('nine', '9')
return int(answer)
def solution(s):
answer = s
num_s = {'zero':0, 'one':1, 'two':2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8, 'nine':9}
for item in num_s.items():
answer = answer.replace(item[0], str(item[1]))
return int(answer)
반복해야하는 코드들이 있으면 반복문으로 최대한 묶어서 코드를 간결하게 짜도록 노력하고 dictionary도 자주 사용해보도록 노력하자!!
잘 보고 갑니다용