Optimized method of cutting/slicing sorted lists

前端 未结 5 682
無奈伤痛
無奈伤痛 2021-01-02 08:10

Is there any pre-made optimized tool/library in Python to cut/slice lists for values \"less than\" something?

Here\'s the issue: Let\'s say I have a list like:

5条回答
  •  萌比男神i
    2021-01-02 08:38

    You can use the bisect module to perform a sorted search:

    >>> import bisect
    >>> a[bisect.bisect_left(a, 6):]
    [7, 9]
    

提交回复
热议问题