Notice
Recent Posts
Recent Comments
Link
유자차의 재테크 공부방
[프로그래머스] 숫자 문자열과 영단어 본문
반응형
팁!
문자열.replace(a, b) : 문자열 안에 있는 a를 b로 치환
풀이 방법
def solution(s):
words = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
for n in words:
s = s.replace(n, str(words.index(n)))
ans = int(s)
return ans
def solution(s):
n2s = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
number = ""
ans = ""
for i in s:
if i.isdigit():
ans += i
else:
number += i
if number in n2s:
ans += str(n2s.index(number))
number = ""
return int(ans)
반응형
'파이썬 > 알고리즘 문제 풀이' 카테고리의 다른 글
[프로그래머스] 크레인 인형뽑기 게임 (0) | 2022.03.05 |
---|---|
[프로그래머스] 키패드 누르기 (0) | 2022.03.04 |
[프로그래머스] 신규 아이디 추천 (0) | 2022.02.28 |
[프로그래머스 : Python3]로또의 최고 순위와 최저 순위 (0) | 2022.02.22 |
[프로그래머스 : python3] 신고 결과 받기 (0) | 2022.02.21 |
Comments