https://school.programmers.co.kr/learn/courses/30/lessons/42578
해시
from collections import defaultdict
def solution(clothes):
count = defaultdict(int)
answer = 1
for c in clothes:
count[c[1]] += 1
for c in count.values():
answer *= (c+1)
return answer-1
각 의상종류에 +1 한 것을 모두 곱하고 1을 뺀 것이 정답
-> 적어도 하나의 의상은 입어야 하기 때문
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
아이디어는 비슷한데, Counter와 reduce를 사용함
reduce(집계 함수, 순회 가능한 데이터, 초기값)