Notice
Recent Posts
Recent Comments
Link
Development
[프로그래머스] 문자열 내 p와 y의 개수 본문
반응형
문자열 안에 있는 p와 y의 개수를 비교하는 문제이다.
def solution(s):
from collections import Counter
a = Counter(s)
if a['y']+a['Y'] == a['p']+a['P']:
return True
else:
return False
counter을 사용하여 풀었다! 공부한걸 써먹자 ㅎㅎ!!
다른사람 코드
def numPY(s):
# 함수를 완성하세요
return s.lower().count('p') == s.lower().count('y')
Counter로 푼 사람들도 많았는데 ,, 이분은 count로 푸셨다. lower은 있었던걸 완전 까먹고있던 함수다ㅠㅠ
기억하자!!
1. s.count()
2. s.lower()
반응형
'코딩테스트 > Python' 카테고리의 다른 글
[프로그래머스] 짝수와 홀수 (0) | 2021.07.29 |
---|---|
[프로그래머스] 문자열을 정수로 바꾸기 (0) | 2021.07.29 |
[프로그래머스] 자릿수 더하기 (0) | 2021.07.29 |
[프로그래머스] 콜라츠 추측 (0) | 2021.07.29 |
[프로그래머스] 평균 구하기 (0) | 2021.07.29 |
Comments