꺼내먹는지식 준
Python Collections 본문
Python Collections Libaray
from collections import Counter
Counter 는 원소의 개수를 세서 dictionary 로 return 해준다.
아주 유용한 기능은 str 의 경우에도 처리가 가능하다는것.
if key in dict:
를 안해도 한줄로 str 의 모든 단어도 count 할 수 있다.
from collections import defaultdict
dictionary 에서 만약 접근한 key 값이 존재하지 않을 때 key error 를 내는 것이 아니라 사전 설정해놓은 값으로 설정
defaultdict(lambda: 0)
이런식으로 설정 가능
from collections import deque
queue 를 호출
원소의 개수가 많아질 수록 list의 append pop 이 아닌, queue 의 사용은 필수이다.
그 이유는 list 의 append 와 pop 은 list 의 크기를 조정하는데 비용이 발생하기 때문이다.
Comments