python等价于std :: lower_bound和std :: upper_bound C ++算法的等效项是什么? [英] What are python's equivalents of std::lower_bound and std::upper_bound C++ algorithms?

查看:587
本文介绍了python等价于std :: lower_bound和std :: upper_bound C ++算法的等效项是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

python是否提供类似于C ++标准库的std::lower_boundstd::upper_bound算法的对排序列表执行二进制搜索的功能?

Does python provide functions for performing binary search on sorted lists, analogous to the std::lower_bound and std::upper_bound algorithms of the C++ Standard Library?

推荐答案

这些函数位于

  • bisect. bisect_left ( a x lo = 0 hi = len(a))是std::lower_bound()的类似物.

    • bisect.bisect_left(a, x, lo=0, hi=len(a)) is the analog of std::lower_bound().

    二等分. bisect_right ( a x lo = 0 hi = len(a))是std::upper_bound()的类似物.

    bisect.bisect_right(a, x, lo=0, hi=len(a)) is the analog of std::upper_bound().

    注意:还有一个功能 bisect (),它是 bisect_right ()的别名.

    Note: there is also a function bisect() which is an alias for bisect_right().

    这篇关于python等价于std :: lower_bound和std :: upper_bound C ++算法的等效项是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆