파이썬2 [프로그래머스] 위장 파이썬 C++ 문제링크 programmers.co.kr/learn/courses/30/lessons/42578 코딩테스트 연습 - 위장 programmers.co.kr Python from collections import defaultdict def solution(clothes): answer = 0 dic=defaultdict(int) for i in clothes: dic[i[1]]+=1 multiple=1 for i in dic: multiple*=dic[i]+1 return multiple-1 아이디어: 경우의 수 세기 문제. 아무것도 안입을 수는 없으므로 옷종류+1을 곱하고 마지막에 1뺌. C++ #include #include #include #include using namespace std; int .. 2021. 5. 3. Python 코딩테스트 끄적끄적 지속적인 업데이트 예정입니다. 1. defaultdict 사용(유사딕셔너리) from collections import defaultdict sample=defaultdict(int) sample['dog'] print(sample.items()) sample['dog']+=1 print(sample.items()) 2. list, dictionary comprehension sample=[x for x in range(10)] print(sample) sample1={x:[] for x in ['a','b','c']} print(sample1) ''' [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] {'a': [], 'b': [], 'c': []} ''' 3. zip : iterable한 객체 .. 2021. 4. 20. 이전 1 다음