문자열 내 p와 y의 개수_프로그래머스_파이썬

  • 나의 풀이
import re
def solution(s):
    return len(re.sub('[^pP]',"",s)) == len(re.sub('[^yY]',"",s))
print(solution("pPoooyY"))
True
  • 다른 사람 풀이
def numPY(s):
    # 함수를 완성하세요
    return s.lower().count('p') == s.lower().count('y')

# 아래는 테스트로 출력해 보기 위한 코드입니다.
print( numPY("pPoooyY") )
print( numPY("Pyy") )
True
False

Comments