동캄의 코딩도장

프로그래머스 level2 [위장] 파이썬 본문

코테/프로그래머스

프로그래머스 level2 [위장] 파이썬

동 캄 2021. 12. 10. 10:35

https://programmers.co.kr/learn/courses/30/lessons/42578

 

코딩테스트 연습 - 위장

 

programmers.co.kr

#프로그래머스  위장
def solution(clothes):
    answer = 1
    lst={}
    for clothe in clothes:
        if clothe[1] in lst:
            lst[clothe[1]]+=1
        else:
            lst[clothe[1]]=1
    for val in lst.values():
        answer*=(val+1)
    return (answer-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

내장 함수를 이용하여 문제를 해결하는 방식도 존재한다.