5. 자료 구조 — Python 3.10.2 문서 5. 자료 구조 이 장에서는 여러분이 이미 배운 것들을 좀 더 자세히 설명하고, 몇 가지 새로운 것들을 덧붙입니다. 5.1. 리스트 더 보기 리스트 자료 형은 몇 가지 메서드들을 더 갖고 있습니다. 이 docs.python.org 강의를 듣다가 잊고 있던 부분 다시 한 번 상기. 강의에서는 pop(0) 보다 pop()이 더 효율적이기 때문에, 리스트를 역순으로 정렬한 뒤 사용하는 풀이를 보여줬다. 리스트를 큐로 사용하는 것도 가능한데, 처음으로 넣은 요소가 처음으로 꺼내지는 요소입니다 (《first-in, first-out》); 하지만, 리스트는 이 목적에는 효율적이지 않습니다. 리스트의 끝에 덧붙이거나, 끝에서 꺼내는 것은 빠르지만, 리스트의 머리에 덧..
functools — Higher-order functions and operations on callable objects — Python 3.10.2 documentation docs.python.org functools.cmp_to_key(func) Transform an old-style comparison function to a key function. Used with tools that accept key functions (such as sorted(), min(), max(), heapq.nlargest(), heapq.nsmallest(), itertools.groupby()). This function is primarily used as a transition tool for pr..
Dictionary는 Hash Table로 구성되어 있는데, 이는 상수 시간으로 접근이 가능하다. Counter의 연산. Counter는 Dictionary의 subclass이다. >>> c = Counter(a=3, b=1) >>> d = Counter(a=1, b=2) >>> c + d # add two counters together: c[x] + d[x] Counter({'a': 4, 'b': 3}) >>> c - d # subtract (keeping only positive counts) Counter({'a': 2}) >>> c & d # intersection: min(c[x], d[x]) Counter({'a': 1, 'b': 1}) >>> c | d # union: max(c[x], d..