https://programmers.co.kr/learn/courses/30/lessons/81301
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 1๋จ๊ฒ - ์ซ์ ๋ฌธ์์ฌ๋ก๊ฐ ์๋จ์ด
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])) # item[0] = key, item[1] = values
return int(answer)
x.replace(a, b) : x์ ์๋ a๋ฅผ b๋ก ๋ฐ๊ฟ์ฃผ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ
x.items() : tuple x์ ์๋ key, value ๋ฐํ
'๐๏ธ Algorithm > โฌ ํ๋ก๊ทธ๋๋จธ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Programmers] [Python] Level1_๋ชจ์๊ณ ์ฌ (0) | 2022.03.08 |
---|---|
[Programmers] [2020 ์นด์นด์ค ์ธํด์ญ] [Python] Level1_ํคํจ๋ ๋๋ฅด๊ธฐ (0) | 2022.03.07 |
[Programmers] [Python] Level1_2016 (0) | 2022.03.07 |
[Programmers] [Python] Level1_์ฒด์ก๋ณต (0) | 2022.03.06 |
[Programmers] [2021 kakao blind recruitment] [Python] Level1_์ ๊ท ์์ด๋ ์ถ์ฒ (0) | 2022.02.26 |