본문 바로가기

성우리뷰

[프로그래머스] 둘만의 암호

def solution(s, skip, index):
    answer = ''
    full_text = 'abcdefghijklmnopqrstuvwxyz'
    adapt_text = ''
    
    for i in range(len(full_text)):
        if full_text[i] in skip:
            continue
        adapt_text += full_text[i]

    for i in range(len(s)) :
        if s[i] in adapt_text :
            idx = adapt_text.index(s[i]) + index
        # if idx >= len(full_text) :
        idx = idx % len(adapt_text)
        answer += adapt_text[idx]
        
    return answer

 

딱히 어려운 건 없지만, 알아두면 좋은 함수 2개를 적어둔다.

1) index 추출

list 내의 한 요소를 알고 있는데, 해당 요소의 index가 알고싶은 경우

list_name.index(element_name)

2) 아스키코드

chr(65) # A
chr(97) # a
ord("A") # 65
ord("a") # 97

'성우리뷰' 카테고리의 다른 글

(softeer) 로봇이 지나간 길  (0) 2023.04.12
[softeer] 업무처리  (0) 2023.04.10
[softeer] 성적평가  (0) 2023.04.03
[Softeer] 금고 관리  (0) 2023.03.27
현대 이미지 프로세싱  (0) 2022.03.22