[프로그래머스/파이썬] Level 1 문자열 내 p와 y의 개수
https://programmers.co.kr/learn/courses/30/lessons/12916
문제풀이
간단한 문제였다.
프로그래머스에서 찾은 더 간단한 코드는 문자열을 소문자로 다 바꿔주고 각각 p와 y개수를 구해, 바로 리턴해주었다.
소스코드
def solution(s):
p_cnt,y_cnt=0,0
for i in s:
if i=="p" or i=="P":
p_cnt+=1
elif i=="y" or i=="Y":
y_cnt+=1
return p_cnt==y_cnt
더 간단한 코드
def numPY(s):
# 함수를 완성하세요
return s.lower().count('p') == s.lower().count('y')
Author And Source
이 문제에 관하여([프로그래머스/파이썬] Level 1 문자열 내 p와 y의 개수), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@bye9/프로그래머스파이썬-Level-1-문자열-내-p와-y의-개수저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)