答案 0 :(得分:1)
如果range是输入列表,而point是您要查找间隔数的位置。
例如:ranges = [[0,5],[3,6],[-2,0],[4,10]]
,point = 3
这可能是一个简单的代码,它返回一个点的间隔数。
>>> def count_intervals(ranges,point):
... count = 0
... for range in ranges:
... if range[0] <= point and range[1] >= point:
... count += 1
... return count
少量示例输出
>>> print(count_intervals([[0,5],[3,6],[-2,0],[4,10]],3))
2
>>> print(count_intervals([[0,5],[3,6],[5,12],[4,5],[7,13]],8))
2
>>> print(count_intervals([[0,5],[3,6],[5,12],[4,9],[7,13]],8))
3