Having a list like this
[207, 357, 470, 497, 537]
where each number denotes the boundary of an interval (0
being implicit at the beginning of the list), what is a pythonic way of finding out to which interval a given number n
belongs to?
So the intervals are
0: (0, 207)
1: (208, 357)
2: (358, 497)
3: (498, 537)
If n=0
, then the corresponding interval is 0
, for n=360
, it's 2
.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…