📌  相关文章
📜  在以某个值开头的值列表上进行聚类 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:13.290000             🧑  作者: Mango

代码示例1
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))