转发:http://www.cnblogs.com/skydesign/archive/2011/09/02/2163592.html

先看看模块的结构:

      python bisect模块

       前面五个属性大家感兴趣可以打出来看看数值,这里就不介绍了。

       先说明的是,使用这个模块的函数前先确保操作的列表是已排序的。

      python bisect模块

       先看看 insort  函数:

       python bisect模块

       其插入的结果是不会影响原有的排序。

       再看看 bisect  函数:

       python bisect模块

       其目的在于查找该数值将会插入的位置并返回,而不会插入。

       接着看 bisect_left 和 bisect_right 函数,该函数用入处理将会插入重复数值的情况,返回将会插入的位置:

       python bisect模块

       其对应的插入函数是 insort_left  和 insort_right :

       python bisect模块

       可见,单纯看其结果的话,两个函数的操作结果是一样的,其实插入的位置不同而已。

相关文章:

  • 2022-02-03
  • 2022-12-23
  • 2022-12-23
  • 2021-06-20
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
  • 2022-03-08
  • 2022-12-23
相关资源
相似解决方案