성우리뷰

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

두원공대88학번뚜뚜 2023. 4. 8. 18:14
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