What are the python equivalents for std :: lower_bound and std :: upper_bound c ++ algorithms?

Does python provide functions for performing binary searches on sorted lists, similar to algorithms std::lower_boundand the std::upper_boundstandard C ++ library?

+4
source share
1 answer

These functions are in the bisect module :

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

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

. bisect(), bisect_right().

+5

All Articles