cluster on lists of values that start with a certain value

The solution for “cluster on lists of values that start with a certain value” can be found here. The following code will assist you in solving the problem.

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: yield group numbers = [123, 124, 128, 160, 167, 213, 215, 230, 245, 255, 257, 400, 401, 402, 430] dict(enumerate(grouper(numbers), 1))

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in