문제 바로가기
https://school.programmers.co.kr/learn/courses/30/lessons/42578
ex)
| clothes | 출력 |
|---|---|
| [["yellow_hat", "headgear"], ["blue_sunglasses", "eyewear"], ["green_turban", "headgear"]] | 5 |
| [["crow_mask", "face"], ["blue_sunglasses", "face"], ["smoky_makeup", "face"]] | 3 |
각 의상 종류를 key 값으로, 각 의상 종류마다 포함하고 있는 의상 이름의 갯수를 value 값으로 갖는 딕셔너리 dict_clothes를 생성한다.각 의상 종류의 value값에 +1을 해준 값을 다 곱해준다. ⇒ 조합으로 생각-1을 해준다.def solution(clothes):
dict_clothes={}
for i in range(len(clothes)):
if clothes[i][1] not in dict_clothes:
dict_clothes[clothes[i][1]]=1
else:
dict_clothes[clothes[i][1]]+=1
mul=1
for num_clothes in dict_clothes.values():
mul*=(num_clothes+1)
return mul-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