[Python] 프로그래머스 - Level1 - 문자열 내 p와 y의 개수

강주형·2022년 8월 12일
0

https://school.programmers.co.kr/learn/courses/30/lessons/12916

연습문제

def solution(s):
    count = 0
    for i in s.lower():
        if i == 'p':
            count += 1
        elif i == 'y':
            count -= 1
    return bool(not count)

0은 False, 나머지 숫자는 True로 반환되는 것을 이용했음


타인 코드
def numPY(s):
    return s.lower().count('p') == s.lower().count('y')

count()를 잊고 있었네..

profile
Statistics & Data Science

0개의 댓글