문자열 내 p와 y의 개수

Mkim4·2023년 6월 19일
1

프로그래머스-문자열 내 p와 y의 개수(링크 바로가기)

(나의 풀이방법)

def solution(s):
    count_p = 0
    count_y = 0
    list_s = list(s)
    
    for i in list_s:
        if ord(i) == 80 or ord(i) == 112:
            count_p += 1
        elif ord(i) == 89 or ord(i) == 121:
            count_y += 1
            
    if count_p == count_y:
        return True
    else:
        return False
    
    #"p"=====>112
    #"P"=====>80
    #"y"=====>121
    #"Y"=====>89

(다른 사람의 풀이방법)

def solution(s):
    return s.lower().count('p') == s.lower().count('y')
profile
귀요미 개발자

0개의 댓글