04.3 bisect可维护序列
作者:互联网
代码
bisect 有用二分查找实现,故效率挺高,但是需要的是升序的有序序列
# 可维护序列
import bisect
from collections import deque
# deque 队列
# 维护已排序的序列-升序
# 二分查找
# 创建一个队列
inter_list = deque()
# insort 插入数据
bisect.insort(inter_list, 3)
bisect.insort(inter_list, 2)
bisect.insort(inter_list, 5)
bisect.insort(inter_list, 1)
bisect.insort(inter_list, 6)
print(inter_list) # [1, 2, 3, 5, 6]
# bisect 查
print(bisect.bisect(inter_list, 6))
print(bisect.bisect_right(inter_list, 3))
标签:deque,bisect,insort,list,print,04.3,序列,inter 来源: https://www.cnblogs.com/zy7y/p/14193833.html