728x90
320x100
def solution(clothes):
answer = 0
cntList = []
clotheslist = {}
for n, t in clothes:
if t in clotheslist:
clotheslist[t].append(n)
else:
clotheslist[t] = [n]
for cloth in clotheslist:
cntList.append(len(clotheslist[cloth]))
print(clotheslist, cntList)
# 옷종류가 하나일 때
if len(cntList) == 1:
return cntList[0]
else :
cnt = 1
for i in cntList:
cnt *= i
return sum(cntList) + cnt
return answer
처음에 이렇게 구현했는데 테스트는 통과하고 제출은 통과못함. 소스도 너무 길고...문제가 있다.


def solution2(clothes):
dict = {}
# 옷종류 : 갯수 ex) {'headgear': 2}
for clothe, type in clothes:
dict[type] = dict.get(type, 0) + 1
answer = 1
for type in dict:
answer *= (dict[type] + 1)
print(answer, dict[type] + 1)
return answer - 1 #아무 것도 안입는 경우는 없으니 -1
728x90
320x100
'💻 하나씩 차곡차곡 > 프로그래머스 (Python)' 카테고리의 다른 글
[프로그래머스/Lv.1/Python] 베스트앨범 (0) | 2024.01.11 |
---|---|
[프로그래머스/Lv.1/Python] 폰켓몬 (0) | 2024.01.10 |
[프로그래머스/Lv.2/Python] 전화번호 목록 (0) | 2024.01.08 |
[프로그래머스/Lv.1/Python/해시] 완주하지 못한 선수 (0) | 2024.01.05 |
[프로그래머스/Lv.1/Python] [PCCP 기출문제] 1번 / 붕대 감기 (0) | 2024.01.04 |