위장_파이썬

Minji·2022년 4월 12일
0

코딩테스트 연습

목록 보기
2/11

python dictionary

딕셔너리 안에 찾으려는 Key 값이 없을 경우 미리 정해 둔 디폴트 값을 대신 가져오게 하고 싶을 때에는 get(x, '디폴트 값')

즉,
dictionary={"A":"a","B":"b"}일 때,
dictionary.get(A,0)하면 a가 나오지만
dictionary.get(C,0)하면 키값 C가 없으므로 0으로 출력됨

def solution(clothes):
    answer = 1
    dictionary={}

    for cloth,type in clothes:
        dictionary[type]=dictionary.get(type,0)+1

    for type in dictionary:
        answer*=(dictionary[type]+1) #입냐마냐
    
    
    return answer-1
profile
매일매일 성장하기 : )

0개의 댓글