def solution(s):
count = 0
for i in range(len(s)):
if s[i] == 'p' or s[i] == 'P':
count += 1
elif s[i] == 'y' or s[i] == 'Y':
count -= 1
return True if count == 0 else False
문자열을 소문자나 대문자로 통일시키고, count(문자열) 을 하면 해당 문자의 갯수를 리턴해준다. 반복을 돌릴 필요가 없었다.