def group_runs(li, tolerance=2):
    out = []
last = li[0]
for x in li:
    if x - last > tolerance:
        yield out
out = []
out.append(x)
last = x
yield out
Group consecutive integers and tolerate gaps of 1