Language/Python

[Python / 프로그래머스 level 1] 시저 암호

ej503 2021. 6. 27. 09:42

def solution(s, n):
    lower_list = "abcdefghijklmnopqrstuvwxyz"
    upper_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    
    result = []
    
    for i in s:
        if i is " ":
            result.append(" ")
        elif i.islower() is True:
            new = lower_list.find(i) + n
            result.append(lower_list[new % 26])
        else:
            new = upper_list.find(i) + n
            result.append(upper_list[new % 26])
    return "".join(result)