defaultdict (1) 썸네일형 리스트형 defaultdict 파이썬에는 유용한 패키지들이 내장되어있다. 자주 쓰는 내장 패키지 중 하나는 collections이다. 이 패키지가 지원하는 defaultdict라는 자료구조에 대해 알아보자. # 기존 dictionary를 사용해서, 리스트에 대한 통계를 내고 싶을 때 ls = [{'red': 5}, {'blue': 3}, {'green': 1}, {'red': 3}] count_dict = {} for l in ls : for color, count in l.items() : if color not in count_dict.keys() : # count_dict의 key 안에 아직 해당 칼라에 대한 정보가 없을 때 count_dict[color] = count # 처음 들어온 color의 count를 default i.. 이전 1 다음