02 2018 档案
摘要:import heapq heap = [] heapq.heappush(heap, item)#将item加入heap,保持堆结构 heapq.heappop(heap)#弹出堆顶最小元素,如果heap为空,抛出一个IndexError,不弹出只调用这个最小元素,使用heap[0] heapq.heappushpop(heap, item)#将item加入heap,并弹出堆顶最小元素,比h...
阅读全文
摘要:collections的常用类型有: 计数器(Counter) 双向队列(deque) 默认字典(defaultdict) 有序字典(OrderedDict) 可命名元组(namedtuple) 使用以上类型时需要导入模块 from collections import * 详见http://blo
阅读全文
摘要:句尾没有逗号 或者可以直接用append(),避免逗号的问题
阅读全文