코딩테스트/Python

[프로그래머스/Python] 문자열 내 p와 y의 개수

짐니♡ 2025. 9. 22. 21:44

 

 

def solution(s):

    count1 = 0 
    count2 = 0
    
    for i in range(len(s)):
        if s[i] in ['p', 'P']:
            count1 += 1
        elif s[i] in ['y', 'Y']:
            count2 += 1

    
    if(count1 == count2 or (count1 == 0 and count2 == 0)):
        return True
    else:
        return False

 

파이썬에서 리스트 안에 p랑 P 안에 있냐고 물어볼거면 or이 아니라

in ['p','P']로 해야함 !!!