接受唯一整数的排序列表的函数 count_numbers
function count_numbers that accepts a sorted list of unique integers
实现函数 count_numbers,它接受经过排序的唯一整数列表,并在使用时间方面高效地计算小于参数 less_than.[=12 的列表元素的数量=]
例如count_numbers([1, 3, 5, 7], 4) 应该return 2 因为有两个列表元素小于4.
**def count_numbers(sorted_list, less_than):
pass
if __name__ == "__main__":
sorted_list = [1, 3, 5, 7]
print(count_numbers(sorted_list, 4)) # should print 2**
from bisect import bisect_left
def count_numbers(sorted_list, less_than):
i = bisect_left(sorted_list, less_than)
return i
if __name__ == "__main__":
sorted_list = [1, 3, 5, 7]
print(count_numbers(sorted_list, 0))
实现函数 count_numbers,它接受经过排序的唯一整数列表,并在使用时间方面高效地计算小于参数 less_than.[=12 的列表元素的数量=]
例如count_numbers([1, 3, 5, 7], 4) 应该return 2 因为有两个列表元素小于4.
**def count_numbers(sorted_list, less_than):
pass
if __name__ == "__main__":
sorted_list = [1, 3, 5, 7]
print(count_numbers(sorted_list, 4)) # should print 2**
from bisect import bisect_left
def count_numbers(sorted_list, less_than):
i = bisect_left(sorted_list, less_than)
return i
if __name__ == "__main__":
sorted_list = [1, 3, 5, 7]
print(count_numbers(sorted_list, 0))