Dec-20-2018, 12:29 AM
(This post was last modified: Dec-20-2018, 12:29 AM by Gribouillis.)
I suggest this
import bisect tab_list = [0, 4, 11, 18, 26, 33, 40, 47, 54, 62, 69, 77, 84, 92, 99, 107, 114, 122, 130, 138, 146, 154, 163, 171, 180, 189, 198, 207, 216, 226, 236, 246, 257, 268, 279, 291, 303, 316, 329, 345, 358, 375, 392, 412, 433, 457, 485, 518, 560, 620, 735] def get_rst(value): """computes the largest number in tab_list <= value. Works if tab_list[0] <= value""" return tab_list[bisect.bisect_right(tab_list, value) - 1] # test this for i in range(20): print(i, get_rst(i))
Output:0 0
1 0
2 0
3 0
4 4
5 4
6 4
7 4
8 4
9 4
10 4
11 11
12 11
13 11
14 11
15 11
16 11
17 11
18 18
19 18