나의 풀이
def solution(cipher, code):
answer = ''
for i in range(code-1, len(cipher), code):
answer+=cipher[i]
return answer
다른 사람의 풀이
def solution(cipher, code):
answer = cipher[code-1::code]
return answer
▶ 문자열도 슬라이싱이 가능하다는 사실
▶ cipher[code-1: :code] → 끝까지 슬라이싱 하되, code만큼 점프한다.
'프로그래머스(파이썬) > LV.0(파이썬)' 카테고리의 다른 글
인덱스 바꾸기 - join함수, list(my_string) (0) | 2022.11.21 |
---|---|
피자 나뉘 먹기(3) - 나누어 떨어진다는 개념 (0) | 2022.11.18 |
369게임 - lambda★ (0) | 2022.11.18 |
가까운 수 → "특이한 정렬"과 매우 유사 (0) | 2022.11.18 |
삼각형의 완성조건(1) (0) | 2022.11.18 |