test_list = [1, 2, 3, 8, 10, 15, 16, 17, 18, 22, 23, 27, 30, 31]
max_diff = 2
splited_list = []
prev_element = float('-inf')
for element in test_list:
    if element - prev_element > max_diff:
        splited_list.append([])
splited_list[-1].append(element)
prev_element = element
print(splited_list)
How to split a sorted list into sub lists when two neighboring value difference is larger than a threshold