[나의 풀이]
def solution(s):
s = s.lower()
countP = 0
countY = 0
for i, j in enumerate(s):
print(i, j)
if j == "p":
countP += 1
elif j == "y":
countY += 1
print(countP)
print(countY)
if countP == countY:
return True
else:
return False
print(solution("pPooY"))
[다른 풀이]
def numPY(s):
return s.lower().count('p') == s.lower().count('y')
from collections import Counter
def numPY(s):
c = Counter(s.lower())
return c['y'] == c['p']
def numPY(s):
if(s.upper().count('P')==s.upper().count('Y')):
return True
return False
'workSpace > ALGORITHM' 카테고리의 다른 글
[Python] 가운데 글자 가져오기 (0) | 2020.12.20 |
---|---|
[Python] 같은 숫자는 싫어 (0) | 2020.12.20 |
[Python] 약수의 합 (0) | 2020.12.18 |
[Python] 서울에서 김서방 찾기 (0) | 2020.12.17 |
[Python] 수박수박수박수박수? (0) | 2020.12.17 |