사용언어 : python
replace
를 사용하여 영단어를 해당하는 값으로 바꾸어줌
영단어와 num을 각각 list
를 주어 반복문을 돌렸지만
다른 사람들은 dictionary
를 사용하여 key
, value
로 해결
def solution(s):
num_string = ["one", "two", "three", "four",
"five", "six", "seven", "eight", "nine", "zero"]
num = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
for x, y in zip(num_string, num):
s = s.replace(x, y)
answer = int(s)
return answer