기억보다 기록을

[Python]Collections.counter() , defaultdict() / 활용예제 링크 본문

카테고리 없음

[Python]Collections.counter() , defaultdict() / 활용예제 링크

juyeong 2023. 2. 22. 20:57
반응형

Collections.counter() 로 가장 많은 데이터와 가장 적은 데이터의 수를 리턴할 수 있다. 

 -> 제일 흔한 elements 리턴해 근데 나는 딕셔너리 성질을 가지고 있으니 키/밸류로 알려줘

 

 

 

 

defaultdict()

-> 매개변수의 default value를 초기값으로 지정 : 매개변수 타입에는 int, list, set 등 다양함

-> 처음 키를 지정할 때 값을 할당하지 않으면 해당 키의 값을 디폴트값으로 지정함

-> 키의 개수를 세거나, 항목을 정리할 때 주로 사용됨 

 

 

활용문제 :

https://juyeongpark.tistory.com/131

 

 

 

출처: 

https://docs.python.org/3/library/collections.html#collections.Counter

https://dongdongfather.tistory.com/69

 

 

반응형