π‘ Python 3
μμ₯ [Link]
κ²½μ°μ μλ₯Ό νμ©ν λ¬Έμ
μ£Όμ΄μ§ μμ μ’ λ₯μ κ°μ + 1(μ μ§ μλ κ²½μ°)
λ‘ μ£Όμ΄μ§ μμ μ’ λ₯λ€μ μλ₯Ό κ³±νμ¬ ν΄κ²°
def solution(clothes):
from collections import defaultdict
check = defaultdict(int)
for v, k in clothes:
check[k] += 1
count = 1
for i in list(check.values()):
count *= (i + 1)
return count - 1
Counter
μreduce
λ₯Ό μ μ νκ² νμ©ν μ½λ
μ΄λ²μ μκ³ λ¦¬μ¦ μ€ν°λμμreduce
μκ² λμλλ°.. μ μ©μ λͺ»ν΄λ΄€λ€ !!
μ΄λ² λ¬Έμ νλ©΄μ νλ²λ λ°°μ λ€ γ γ
def solution(clothes):
from collections import Counter
from functools import reduce
cnt = Counter([kind for name, kind in clothes])
answer = reduce(lambda x, y: x*(y+1), cnt.values(), 1) - 1
return answer