https://school.programmers.co.kr/learn/courses/30/lessons/120894
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
def solution(numbers):
nums = ["zero","one","two","three","four","five","six","seven","eight","nine"]
for index, num in enumerate(nums):
numbers = numbers.replace(num, str(index))
return int(numbers)
enumerate와 replace 함수를 쓰면 간단히 끝나는 문제였다.
replace:
replace(현재 문자, 변경할 문자, 변경횟수)
변경횟수 디폴드 값은 -1이다. 현재 문자열 전체를 반환한다.
enumerate:
리스트의 원소에 순서값을 부여해주는 함수다.
'[개발]programmers > Python3' 카테고리의 다른 글
Lv.1_모의고사 (0) | 2023.06.30 |
---|---|
Lv.0_유한소수 판별하기 (0) | 2023.06.30 |
Lv.0_진료순서 정하기 (0) | 2023.06.16 |
Lv.0_2차원으로 만들기 (0) | 2023.06.16 |
Lv.0_중복된 문자 제거 (0) | 2023.06.16 |