def count_numbers(sorted_list, less_than): count = 0 length = len(sorted_list) if not length: return 0 if length == 1: return count + 1 if sorted_list[0] < less_than else count elif sorted_list[-1] < less_than: return count + length elif sorted_list[0] > less_than: return count half = length//2 return count_numbers(sorted_list[:half], less_than) + count_numbers(sorted_list[half:], less_than) sorted_list = [1, 2, 3, 3, 3, 4, 4 ,5, 5, 5, 5, 7] print(count_numbers(sorted_list, 5))