๋ฌธ์์ด์ ๋ณ๊ฒฝํ๋ ํจ์๋ก, ๋ฌธ์์ด ์์์ ํน์ ๋ฌธ์๋ฅผ ์๋ก์ด ๋ฌธ์๋ก ๋ณ๊ฒฝํ๋ ๊ธฐ๋ฅ
๋ฌธ์์ด ์์๊ณผ ๋ฌธ์์ด ๋์์ ํน์ ๋ฌธ์๋ฅผ ์ ๊ฑฐ
์ด..์ด๋ ต๋ค.. ๋ฌธ์ ๋ง ๋ณด๊ณ ์ฌ์ธ ์ค..
๊ทธ๋๋ ํ์๋ค.. ํจ์จ์ ์ธ ์ฝ๋๋ ์ ๋ ์๋๋ผใ
ใ
ใ
๋ถ๋๋ฝ๋ค ใ
ใ
;;;;
replace ํจ์๋ฅผ ์๊ฐํด๋ด๋๊ฒ ์์ด๋์ด์๋ ๊ฒ ๊ฐ๋ค.
< ๋ด ๋ต์ >
def solution(s):
d = [['0', 'zero'], ['1', 'one'], ['2', 'two'], ['3', 'three'], ['4', 'four'], ['5', 'five'], ['6', 'six'],
['7', 'seven'], ['8', 'eight'], ['9', 'nine']]
s = list(s)
answer = ''
ss = []
for i in range(len(s)):
for j in range(len(d)):
if s[i] == d[j][0]:
for k in range(len(d[j][1])):
ss.append(d[j][1][k])
break
else:
ss.append(s[i])
a = ''
for j in range(len(ss)):
a = a + ss[j]
for k in range(len(d)):
if a == d[k][1]:
answer = answer + d[k][0]
a = ''
return int(answer)
๋ ์ด๋ ๊ฒ ๊ธธ์๋๋ฐ..
๋ค๋ฅธ ์ฌ๋ ํ์ด ๋ณด๊ณ ํํ์๋ค ๐
๋๋ ์ฒ์์ ์ฌ์ ์ผ๋ก ๋๊ณ ํ์๋๋ฐ ๋๋ฌด ๋ณต์กํ๊ฒ ์๊ฐํ๋์ง ๋งํ์ ์ค๊ฐ์ ๋ฆฌ์คํธ๋ก ๋ฐ๊ฟจ๋๋ฐ.. ์ด๋ ๊ฒ๋ ๋๊ตฌ๋..
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)
๋๋
def solution(s):
words = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
for i in range(len(words)):
s = s.replace(words[i], str(i))
return int(s)