목록개발/Data Structure (2)
Deque (double-ended queue) - 양방향에서 데이터 처리 가능 - Python 리스트와 비슷 1. collections.deque Method 1) append(x) 2) appendleft(x) 3) extend (iterable) # 예제3-1. list.append() vs deque.append() import collections # list lst = ['a', 'b', 'c'] lst.extend('d') print(lst) ''' 결과 ['a', 'b', 'c', 'd'] # collections.deque deq = collections.deque(['a', 'b', 'c']) deq.extend('d') print(deq) ''' 결과 deque(['a', 'b', '..
컨테이너에 동일한 값의 자료가 몇개인지 파악할 때 사용하는 객체 1. List import collections lst = ['aa', 'cc', 'dd', 'aa', 'bb', 'ee'] print(collections.Counter(lst)) ----- 결과 Counter({'aa': 2, 'cc': 1, 'dd': 1, 'bb': 1, 'ee': 1}) 2. Dict - 요소 갯수 많은 것 부터 출력 import collections print(collections.Counter({'a': 3, 'b': 2, 'c': 4})) ----- 결과 Counter({'c': 4, 'a': 3, 'b': 2}) 3. 값 = 요소 개수 import collections c = collections.Counte..