In [24]: import bisect
In [25]: a=[1,2,3,6,7]
# bisect(list,obj_new)返回插入值后仍保持的排序的索引位置
In [26]: bisect.bisect(a,5)
Out[26]: 3
# bisect(list,obj_old)有相同对象,默认在返回向相同对象右边插入值后,返回的索引位置
In [27]: bisect.bisect(a,3)
Out[27]: 3
# bisect_right(list,obj_old)有相同对象,向相同对象的右边插入值,返回的索引位置
In [28]: bisect.bisect_right(a,3)
Out[28]: 3
# bisect_left(list,obj_old)有相同对象,向相同对象的左边插入值,返回的索引位置
In [29]: bisect.bisect_left(a,3)
Out[29]: 2
#不会检查是否排序
In [32]: b=[5,3,8,1]
In [33]: bisect.bisect(b,4)
Out[33]: 2
#insort(list,obj)
In [41]: bisect.insort(a,5)
In [42]: a
Out[42]: [1, 2, 3, 5, 6, 7]
# 实验对象是元组也OK
In [43]: c=(1,2,6,7)
In [44]: bisect.bisect(c,5)
Out[44]: 2