Read the Big-O
Sort, Then Search
values and limits both have n items. Sort once, then a binary search per limit: the total?1import bisect
2
3def count_below(values, limits):
4 values = sorted(values)
5 return [bisect.bisect_left(values, x) for x in limits]