July 08, 2021
def solution(s):
words = {'zero': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}
for i in range(1, len(s)):
if (s.isdigit()):
return s
if not s[i - 1].isdigit():
for w in words.keys():
if (w.startswith(s[i - 1] + s[i])):
s = s.replace(w, str(words[w]))
break
return 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)