数据结构
双端队列
可从队列2端进行添加和移除数据,效率比list高。...next_item = heapq.heappop(q) print(next_item)# 结果:# (1, 'eat')# (2, 'code')# (3, 'sleep')# 将一个数组初始化为堆结构...,输出:0bisect.bisect_right([1,2],1) # 不插入值,返回右侧的索引,输出:1# 下面两行就是insort_right和bisect_right的别名bisect.insort...0,30]内的偶数# 随机返回集合中的一个元素random.choice([1,2,3])# 随机打乱集合,无返回arr=[1,2,3,4,5]random.shuffle(arr)print(arr)# 从列表中随机返回...'B') ('A', 'C') ('A', 'D') ('B', 'B') ('B', 'C') ('B', 'D') ('C', 'C') # ('C', 'D') ('D', 'D')
相当于多增加