counter (2) ์ธ๋ค์ผํ ๋ฆฌ์คํธํ [ํ๋ก๊ทธ๋๋จธ์ค] ๋ฌธ์์ด ๋ด 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() [ํ๋ก๊ทธ๋๋จธ์ค] ์์ฅ ใ ใ ๋์ ๋๋ฆฌ๊น์ง ๋ง๋ค์๋๋ฐ ๊ณ์ฐ์ ์ด๋ป๊ฒ ํ ๊ฑด์ง ๊ณ ๋ฏผํ๋ค๊ฐ.. ๋ธ๋ก๊ทธ๋ดค๋ค ใ .. ๋ธ๋ก๊ทธ์์ ๊ณ์ฐ ๋ฐฉ๋ฒ๋ง ๋ณด๊ณ ์ฝ๋๋ ๋ด๊ฐ ์ง๋ดค๋ค!ใ ์ค๋ช ์ ์ฝ๋ ์์ ๋ค์ด๊ฐ์๋ค. ๋ด ์ฝ๋ def solution(clothes): dic = {} sol=1 #์ข ๋ฅ๋ฅผ key, ์๋ฅผ value๋ก ๋์ ๋๋ฆฌ๋ฅผ ๋ง๋ค์ด์ค๋ค. for key in clothes: if key[1] in dic: dic[key[1]]+=1 else: dic[key[1]] = 1 # ๊ฐ ์ข ๋ฅ๋ณ๋ก ์ ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๊ณฑํด์ค๋ค. ๋ง์ง๋ง์ ์ ๋ถ ์ ์ง ์๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๋นผ์ค๋ค. for key in dic: sol*=dic[key]+1 return sol-1 ๋ค๋ฅธ์ฌ๋ ์ฝ๋ def solution(clothes): from collections import Coun.. ์ด์ 1 ๋ค์