def grouper(iterable):
    prev = None
group = []
for item in iterable:
    if not prev or item - prev <= 15:
        group.append(item)
else:
    yield group
group = [item]
prev = item
if group:
    pass
Finding clusters of numbers in a list